I have a collection named ‘Foo’. I’d like to update every document in the Foo collection that has a bar value of 100 to 1000. What’s the best way to run this update in MongoDB to get an efficient update?
I have a collection named ‘Foo’. I’d like to update every document in the
Share
Use the
$setoperator to do that:The fourth parameter sets the
multioption to true so that you update all matching documents, not just the first one.3.2 UPDATE
Recent MongoDB versions provide an
updateManymethod that is a bit more intuitive: