2
votes

I have sample products table and would like to update multiple documents using _id field. Every time, I try this it only updates the first doc in the $in clause I mentioned , not updating all.

db.products.update({_id:{$in:[ObjectId("507d95d5719dbef170f15bff"),
ObjectId("507d95d5719dbef170f15c01"), ObjectId("507d95d5719dbef170f15c00")]}},
{$set:{'monthly_price':7865}}, {multi:true})
3
this query works for me. you have some other problem. - user10

3 Answers

0
votes

You can first try running find on the products table to make sure that all the object ids actually exist.

You can also try explain command

0
votes

give this a try:

db.<collection>.update( { query }, {$set: {monthly_price:7865}}, false, true)
0
votes

I think the object id's which you have given doesn't exist in the collection.
I tried using the following query and it worked for me.

db.test.update({_id:{$in:[ObjectId("57b33483e5b9ce24f4910855"),
                          ObjectId("57b33483e5b9ce24f4910856"),
                          ObjectId("57b33489e5b9ce24f4910857"),
                          ObjectId("57b33491e5b9ce24f4910858")
                         ]
                     }
                 },
                 {$set{'isCurrentStatus':true}}, 
                 {multi:true}
              )

Query result