如何在 MongoDB Compass 工具中执行更新($set)查询?

我是新的 MongoDB 指南针工具,并试图更新我的集合中的一个字段。请有人建议更新查询必须写在哪里。在工具中找不到任何选项或窗格来编写自定义查询,无论是选择还是更新。

在默认窗口中,只能找到选择/投影/限制选项。 非常感谢你的帮助。

36129 次浏览

Just move your mouse over a document and find a little pencil. You will enter in update mode. You can change fields, values, arrays, etc.

In the latest version, there is a "_MongoSH" in the bottom left corner of the window. Thx to @Boštjan Pišler for the hint about a new feature.

Old answer: I had the same issue, it looks like a simple feature to implement (since document updates are possible) but... AFAIK there is no such option in compass, you can do it through mongodb shell (CLI client).

The tool was recently updated with a shell (currently in beta) which is accessible by clicking the dark bar on the bottom of the window "_MongoSH"

Mongosh beta tab

You can use mongo MongoSH. Currently its in Beta.

enter image description here

At the bottom left, _MONGOSH:

sample-script-mongo

There you can call updateMany and any other methods available in the MongoSH syntax