MongoDB update multiple subdocuments with or query

前端 未结 5 865
时光取名叫无心
时光取名叫无心 2021-01-27 14:50

I want to make an update query for multiple subdocuments at once. I will be setting all the subdocuments statuses to passive where they satisfy the condition I give on query. <

5条回答
  •  悲哀的现实
    2021-01-27 15:49

    I have run below query. And it is working fantastic.

    db.mm.update( { $or: [ {$and: [{"_id": ObjectId("581d18d41b6c5c752f11c87a")}] }, 
                           {$and: [{"_id": ObjectId("581a1a671b6c5c752f11c87b")}] } 
                   ] 
              }, {$set : {"name": "abc3"}});
    

    If first document not found , second one is updated. And if 1st one is found it is updating only 1st one.

    You can see that in your question -> Error message it is showing "nMatched" : 0 . It is not finding any documents. Confirm all ID's and reference ID's.

提交回复
热议问题