如何在mongodb中用一个查询更新每个文档

如何在mongodb中用一个查询更新每个文档,mongodb,mongoose,Mongodb,Mongoose,我有如下数据。 // first document { "id": 1, "exist": true } // second document { "id": 2, "exist": false } // third document { "id": 3, "exist": false } 当我找到doneAndupdate({u id:2}),{exist:true})时,我希望在一个查询中使用聚合或等将'id:1'的e

我有如下数据。

// first document
  {
    "id": 1,
    "exist": true
  }
// second document
  {
    "id": 2,
    "exist": false
  }
// third document
  {
    "id": 3,
    "exist": false
  }
当我找到doneAndupdate({u id:2}),{exist:true})时,我希望在一个查询中使用聚合或等将'id:1'的exist自动更改为false。

你能推荐一些主意吗?非常感谢你阅读我的问题

我不太明白您想在收藏中更新什么,但要更新许多文档,请使用
updateMany

db.collection.updateMany(
      { violations: { $gt: 1 } }, // the filter to select the wanted document
      { $set: { "exist" : true } } // the change to apply to the field
   );

请避免垃圾邮件问题。你几个小时前已经问过了