流星:变量中的变量

时间:2013-08-25 16:09:27

标签: javascript mongodb meteor

我想在变量的帮助下更新数组,这就是我的源代码:

var y = Flags.findOne({_id: "flagsone"});

// This one works, but I need the other one
// Books.update({_id:book}, {$set: {"score20130901.5": 222}});

   Books.update({_id:book}, {$set: {"score20130901.[y.flag1]": 222}});

有人知道,我如何将变量放在一起?

1 个答案:

答案 0 :(得分:0)

var y = Flags.findOne({_id: "flagsone"});
var props = {};
props["score20130901." + y.flag1] = 222;
Books.update({_id:book}, {$set: props});