[英]how to save() DB.find({}) all models returned with an method in mongoose
I want query to DB and edit some value in the returned Query/rows.我想查询数据库并在返回的查询/行中编辑一些值。 when we have a Query/row we can do it with model.save()
but when we have an array of Query,how we can do it?当我们有一个查询/行时,我们可以用model.save()
来完成,但是当我们有一个查询数组时,我们该怎么做呢? some thing like this:像这样的东西:
let arr=await DB_cat.find({parentId:1})
arr[0].name='first'
arr[1].name='sec'
arr.save()
you can use for of
like this:你可以这样for of
:
let arr=await DB_cat.find({parentId:1})
arr[0].name='first'
arr[1].name='sec'
for (let item of arr){
await item.save()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.