Meteor.users collection 更新时没有减少值

Meteor.users collection not decreasing value on update

我正在调用一个方法:upvoteProject

'upvoteProject'(projectId){
    check(projectId, String);

    // Update project
    let projectById = Projects.findOne({_id: projectId});
    Projects.update({_id: projectId}, {$push: {backers: this.userId}, $inc: {totalBackers: 1}});

    // Register user votes for project
    const FIELDS = {
        availableVotes: 1,
        latestVoteAt: 1,
        canVoteAgainAt: 1,
    };
    let user = Meteor.users.findOne({_id: this.userId}, {fields: FIELDS});
    let $set = {}, $push = {}, $inc = {};

    if (user['availableVotes'] <= 1) {
        $set['canVoteAgainAt'] = getDatePlusTime({days: DATE_LIMIT});
        $push['projectsBacked'] = projectId;
    } else {
        $set['latestVoteAt'] = new Date();
        $inc['availableVotes'] = -1;
    }

    console.log($set, $push, $inc); // { latestVoteAt: Wed Jan 13 2016 18:40:37 GMT-0600 (CST) } {} { availableVotes: -1 }

    Meteor.users.update({_id: this.userId}, {$set: $set}, {$inc: $inc, $push: $push}, function(error, docs){
        console.log(error, docs); // null 1
    });

虽然 Projects.update 效果很好,但我无法让 Meteor.users.update() 降低该值,但是文档确实受到了影响 (null 1)。

我试过不使用任何 $set, $push, $inc objects 而是像这样手动设置字段:

Meteor.users.update({_id: this.userId}, {$set: {fieldName: value} {//...}});

但也没有成功。

其他 Meteor.users.update() 方法虽然有效。

查看文档,http://docs.meteor.com/#/full/update我看到您在单独的对象中应用多个更新:

应该是

Collection.update({ /query/ }, { /update object / }, [选项], 回调)

所以尝试:

Meteor.users.update({_id: this.userId}, {$set: $set, $inc: $inc, $push: $push}, function(error, docs){
        console.log(error, docs); // null 1
    });