Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mongdb$inc(按变量)_Javascript_Mongodb_Meteor - Fatal编程技术网

Javascript Mongdb$inc(按变量)

Javascript Mongdb$inc(按变量),javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我在mongodb上使用meteor。 我正试着用var加上一个数据库 我有一句话是: Accounts.onCreateUser(function(options, user) { user.cheat = "(Member)" user.cost = 1000; user.money = 0; user.rate = 0; user.spy = 200; user.adv = 10

我在mongodb上使用meteor。 我正试着用var加上一个数据库

我有一句话是:

      Accounts.onCreateUser(function(options, user) {


        user.cheat = "(Member)"
        user.cost = 1000;
        user.money = 0;
        user.rate = 0;
        user.spy = 200;
        user.adv = 10; 
        user.power = 25;
        return user;

  })
什么也没发生 我已经定义了所有的变量,但是我似乎不能用一个变量来增加一个变量?可能是语法错误

另一方面,这是可行的:

click: function () {    
Meteor.users.update({_id: this.userId}, {$inc: {'money': 'power'  }});
},

不要引用“电源”!但你也必须首先获得权力的价值

click: function () {    
Meteor.users.update({_id: this.userId}, {$inc: {'money': 25  }});
},

不要引用“电源”!但你也必须首先获得权力的价值

click: function () {    
Meteor.users.update({_id: this.userId}, {$inc: {'money': 25  }});
},

用户任何更新操作中的另一个字段

click: function () {    
  var power = Meteor.user().power;
  Meteor.users.update({_id: this.userId}, {$inc: {'money': power  }});
},
如果您不想增加功率,请使用低于1的功率

    var variable2 = 1;
   click: function () {    
    Meteor.users.update({_id: this.userId}, 
      {$inc: {'money': this.power },$inc: {'power': variable2 } });
    },

用户任何更新操作中的另一个字段

click: function () {    
  var power = Meteor.user().power;
  Meteor.users.update({_id: this.userId}, {$inc: {'money': power  }});
},
如果您不想增加功率,请使用低于1的功率

    var variable2 = 1;
   click: function () {    
    Meteor.users.update({_id: this.userId}, 
      {$inc: {'money': this.power },$inc: {'power': variable2 } });
    },

您不能在任何更新运算符中引用其他字段的值。这在单个查询中是不可能的。您需要使用两个查询-一个用于获取另一个变量的值,另一个用于证明您不能在任何更新运算符中引用另一个字段的值。这在单个查询中是不可能的。您需要使用两个查询—一个用于获取另一个变量的值,另一个用于证明