111

I'm new to MongoDB Compass tool and am trying to update a field in my collection. Please can someone suggest where the update query must be written. Could find no options or panes in the tool to write custom queries be it selection / updation for that matter.

In the Default Window only the selection/projection/restriction options are found. Any help is much appreciated.

Patrick
  • 1,635
  • 2
  • 13
  • 23

5 Answers5

64

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).

Didier L
  • 18,905
  • 10
  • 61
  • 103
Ivan Marjanovic
  • 979
  • 1
  • 9
  • 15
46

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

Boštjan Pišler
  • 842
  • 11
  • 18
22

At the bottom left, _MONGOSH:

sample-script-mongo

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

Worth to mention that before running your commands you may want to change the default DB by using use my-db-name:

use book-store-db
# now the variable `db` points to the book-store-db

db.getCollection("books").updateMany({"year":"2022"}, [{ $set: { "price":"0"} }])
fabriciorissetto
  • 9,475
  • 5
  • 65
  • 73
4

You can use mongo MongoSH. Currently its in Beta.

enter image description here

Mahesh Gareja
  • 1,652
  • 2
  • 12
  • 23
-33

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.

Arturo
  • 27
  • 27
    @Pat is obviously asking about a way to execute an update statement, e.g. `db.collection.updateMany()` – kpentchev Jun 13 '18 at 11:48