我想在变量的帮助下更新数组,这就是我的源代码:
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}});
有人知道,我如何将变量放在一起?
答案 0 :(得分:0)
var y = Flags.findOne({_id: "flagsone"});
var props = {};
props["score20130901." + y.flag1] = 222;
Books.update({_id:book}, {$set: props});