简体   繁体   English

从MongoDB集合中的数组更新对象

[英]Update objects from an array in a MongoDB collection

I need to send an array of objects with respective ID's from client-side code via JSON to an API endpoint that is serve by ExpressJS. 我需要通过JSON将具有相应ID的对象数组从客户端代码发送到ExpressJS提供的API端点。

Now I need to update existing DB objects with all the fields from the array of objects. 现在我需要使用对象数组中的所有字段更新现有的DB对象。 I suppose a for..in loop doesn't look good in this case. 我想在这种情况下,for..in循环看起来并不好看。 Neither did I find a way to update multiple documents in one run. 我也没有找到一种方法来在一次运行中更新多个文档。

I use MongoJS library to work with MongoDB from NodeJS 我使用MongoJS库来处理NodeJS中的 MongoDB

Please advise. 请指教。

may be 也许

db.mycollection.update({name:'some name'}, {$inc:{level:1}}, {multi:true}, function() { // the update is complete });

for mongojs library help you... 对于mongojs图书馆帮助你...

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM