【发布时间】:2016-08-16 11:05:55
【问题描述】:
以前我曾尝试过类似的东西(使用猫鼬和承诺):
var cursor = User.find({email: from.address, token: tokenMatches[1]});
然后
return cursor.update(
{'votes.title': b},
{'$set': { 'votes.$.category': a }}
).then(function (result) {
if(result.nModified == 0) {
return cursor.update({}, {'$push': { votes: { category: a, title: b }}}).then(function (res) {
ServerLog('updatePush', res);
return res;
});
}
});
但它总是在第一次和第二次调用时返回 nModified = 0。直到我发现游标对象实际上没有更新功能。那为什么会这样呢?为什么它没有抛出异常?
【问题讨论】: