gui*_*mie 4 mongoose mongodb node.js mongohq express
我使用以下代码在数组中添加一些内容并增加两个不同的计数器.
该项目已在数组中正确推送,并且pendingSize正确递增.但unRead永远不会增加.它曾经增加,然后今天它停止了.我的mongodb集合中的unRead字段的值(在mongohq上托管)设置为0(数字,而不是字符串)
当我查看我的控制台时,我看到"更新成功".
任何线索为什么它停止工作?
谢谢
Notifications.update({ "id" : theid}, { $push: { pending: notification}, $inc: { unRead : 1 }, $inc: { pendingSize: 1 }}, function(err){
if(err){
console.log('update failed');
callback("Error in pushing." + result.members[i]);
}
else{
console.log('update succes');
callback("Success");
}
});
Run Code Online (Sandbox Code Playgroud)
mpo*_*ien 12
将$ inc的args组合成一个嵌套对象,如下所示:
$inc: { unRead : 1, pendingSize: 1 }
Run Code Online (Sandbox Code Playgroud)
JSON中表示的对象是key:value,其中键必须是唯一的,因此尝试指定多个值$inc将不起作用.
| 归档时间: |
|
| 查看次数: |
4811 次 |
| 最近记录: |