Skip to content Skip to sidebar Skip to footer

Mongodb: Updating Every Document In A Collection

How can I add few elements to an array in every document in a collection? I know how to update documents, but I don't know how to update every document in a collection. For example

Solution 1:

You can get this done with simple update. If you want to update all documents, specify empty condition {} and multi: true like below

db.usertest.update( {}, {$set: {"packs.super-rare": 0}}, false, true)

Empty {} - To match all documents false - upsert true - multi (update multiple documents)

Post a Comment for "Mongodb: Updating Every Document In A Collection"