[英]In Mongoose (node.js MongoDB), how do I perform this update?
{
_id: 'abc123',
reports: [
{ uid: 33, name: 'john' },
{ uid: 215, name: 'jess' },
{ uid: 29, name: 'hal'}
]
}
假設我有上面的文件。
models.Stuff.findOne({_id:'abc123'},function(err,result){
//Got the above record.
});
拿到文件后,如何把所有的“uids”都改成0? 我想通過所有文檔的報告 go 並將所有 uid 更改為 0。
for(i in result.reports){
result.reports[i].uid = 0;
}
result.save();
最好使用pinch.min.js ,這對於這種需求來說非常方便。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.