我正在使用Meteor進行如下更新:Items.update(Session.get('selectedItem'), {'$set': {'directions.0.name': area.value}})但是我在努力如何動態設置方向的數組索引,就像這樣:var index = //a value determined dynamicallyItems.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}})但這是行不通的。關于如何執行此操作的任何想法?
在mongodb更新中使用變量
墨色風雨
2019-10-30 13:03:15