简体   繁体   English

使用mongoose在一个文档中进行多次更新

[英]Multiple updates in one document using mongoose

I want to update multiple values in a single document in one mongoose call. 我想在一个mongoose调用中更新单个文档中的多个值。 Is this possible? 这可能吗?

I have something similar to this: 我有类似的东西:

update = {$inc : { numShown : 1 }, $inc : { secondField.subField : 1 }};
options = {};
MyModel.findByIdAndUpdate(req._id, update, options, function(err){
     if(err){ return console.error(err);}
}

It runs, but doesn't update anything. 它运行,但不更新任何东西。

您需要将两个$inc值组合到一个对象中并引用虚线键:

update = { $inc : { numShown : 1, 'secondField.subField' : 1 } };

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

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