[英]Single line command to iterate & find over multiple items and update Mongoose?
I am wondering if there is specific query line to iterate over mongodb and update? 我想知道是否有特定的查询行可以遍历mongodb并更新? For example, i have data with
'{"name": "A", "age": 23} .... {"name":"Z", "age":25}'
as such, 例如,我有这样的数据,其
'{"name": "A", "age": 23} .... {"name":"Z", "age":25}'
这样,
I want to iterate over with a list of names = [A,B,C,D]
and a list of ages = [30,40,25,23]
. 我想使用名称列表
[A,B,C,D]
和年龄列表= [30,40,25,23]
。
I was thinking about for 我在想
for(var i in names){ people.findoneandupdate("name": names[i], {$set:{"age":ages[i]}})
is there single line query to solve this? 有单行查询来解决这个问题吗?
If you want to update multiple docs in one query you can go with this: 如果您想在一个查询中更新多个文档,可以执行以下操作:
Model.update(conditions, update, options, callback);
Here if you put options = { multi: true } then it will update multiple doc according to given condition 在这里,如果您放置options = {multi:true},那么它将根据给定条件更新多个文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.