![](/img/trans.png)
[英]Accessing nested object in nested array using a variable (MongoDB, Node, Inc)
[英]Mongdb $inc by variable
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;
})
我在mongodb中使用流星。 我正在嘗試使用var將數據庫收入$ inc
我有一行是:
click: function () {
Meteor.users.update({_id: this.userId}, {$inc: {'money': 'power' }});
},
沒有任何反應,我已定義了所有變量,但似乎無法通過變量增加變量? 也許語法錯誤?
另一方面,這可以工作:
click: function () {
Meteor.users.update({_id: this.userId}, {$inc: {'money': 25 }});
},
在任何更新操作中使用另一個字段 。
var variable2 = 1;
click: function () {
Meteor.users.update({_id: this.userId},
{$inc: {'money': this.power },$inc: {'power': variable2 } });
},
或者,如果您不需要強大的功能,請在1個以下使用
var variable2 = 1;
click: function () {
Meteor.users.update({_id: this.userId},
{$inc: {'money': this.power } });
},
不要引用'power'
! 但是,您還必須首先獲取權力的價值。
click: function () {
var power = Meteor.user().power;
Meteor.users.update({_id: this.userId}, {$inc: {'money': power }});
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.