MongoDB update multiple subdocuments with or query

前端 未结 5 911
时光取名叫无心
时光取名叫无心 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:30

    Use method UpdateMany() to update documents. According to framework and langauage this method will be different like Update({multi : true}); or UpdateAll({});`

    For example :

    db.collection.updateMany(
       ,
       
    );
    

    Use $set to write.

    Ref: https://docs.mongodb.com/v3.2/reference/method/db.collection.updateMany/

    try {
       db.restaurant.updateMany(
          { $or: []
          },
          { $set: { "DeviceVersionPairs.$.Status": "passive" } }
       );
    } catch (e) {
       print(e);
    } 
    

提交回复
热议问题