MongoDB Insert a field in all documents in the collection

I am trying to add a new field to all documents in an existing collection.

Database Name = Test Collection Name = Commands

test.teams.update({ } , { $set: { "isGolden": false } } , false, true) 

When I try to use MongoChef, it gives me the following error: enter image description here

What is wrong with this? Thanks

+8
mongodb
source share
3 answers

If you want to update all documents, use something like this:

 db.teams.update({}, {$set: {isGolden: false}}, {multi: true}); 

you select everything by setting filed isGolden to false and doing this update in all documents with multi: true

+21
source share

With MongoDB version 3.2 or later you can do

 db.teams.updateMany({}, {$set: {isGolden: false}}); 

Here's the doc for updateMany function db.collection.updateMany ()

+4
source share

With Studio 3T, you wrote JSON queries in which it needs JSON data, but you don't write JSON Query. You must switch to InteliShell mode, in which your request will be executed in the format you are writing.

Studio 3T InteliShell

+1
source share

All Articles