0

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

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}});

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

4

1 回答 1

0
var y = Flags.findOne({_id: "flagsone"});
var props = {};
props["score20130901." + y.flag1] = 222;
Books.update({_id:book}, {$set: props});
于 2013-08-25T16:29:29.340 回答