我在尝试使用MongoSkin递增1时遇到了困难。
var client = mongoskin.db( // mongodb://server/database?options
'mongodb://localhost/database?auto_reconnect=true&poolSize=1',
{safe: true}
);我将以下对象(文档)添加到我的数据库中-我已经验证了该对象是否在数据库中,并且可以使用$set进行更新。
{loginCount: 0}
当我尝试更新loginCount时,什么也没有发生。
client.collection("user").findOne(user_id.toString(),
{$set: { $inc: { loginCount: 1 }}}, function (err, data) {});发布于 2013-04-12 13:08:34
我已经解决了这个问题:
client.collection("users").updateById(
user_id.toString(),
$inc: {loginCount: 1},
$set: {anotherfield: anothervalue},
function (err) {
// handle error here
}
}独立于$inc运算符使用$set运算符。看起来$inc,将会递增并设置值。
https://stackoverflow.com/questions/15962916
复制相似问题