使用不同的字段更新mongoDB中的多个文档

时间:2018-08-28 09:32:35

标签: mongodb

我想在单个请求中在mongodb集合中执行多个更新。对于Ex

数据库中现有的

{ "_id" : 1, "name" : "Central Perk Cafe", "violations" : 3 }
{ "_id" : 2, "name" : "Rock A Feller Bar and Grill", "violations" : 2 }
{ "_id" : 3, "name" : "Empire State Sub", "violations" : 5 }
{ "_id" : 4, "name" : "Pizza Rat's Pizzaria", "violations" : 8 }

想为每个文档更新特定字段,这些字段是

{ "_id" : 1, "name" : "Central Perk Cafe 1" }
{ "_id" : 2, "name" : "Rock A Feller Bar and Grill 2"}
{ "_id" : 3,  "violations" : 7 }
{ "_id" : 4, "name" : "Pizza Rat", "violations" : 9 }

是否可以在单个请求中实现。我已经通过了update和updateMany方法。但是它会使用相同的字段集更新多个文档。

0 个答案:

没有答案