在mongodb更新中使用变量
- 论坛
- 在mongodb更新中使用变量
7 浏览
在mongodb更新中使用变量
使用Meteor,我试图执行类似以下的更新操作:
Items.update(Session.get('selectedItem'), {'$set': {'directions.0.name': area.value}})
但是我不知道如何动态地设置directions数组的索引,像这样:
var index = //一个动态确定的值 Items.update(Session.get('selectedItem'), {'$set': {'directions[index]name': area.value}})
这不起作用,因为[index]被包含在字符串中。我还尝试了形成一个自定义字符串,像这样:
var string = 'directions.'+itemIndex+'.name' Items.update(Session.get('selectedItem'), {'$set': {string: area.value}})
但那样也不起作用。有什么办法可以解决这个问题吗?