亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在mongodb更新中使用變量

在mongodb更新中使用變量

暮色呼如 2019-12-08 12:08:42
我正在使用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}})但這是行不通的。關于如何執行此操作的任何想法?
查看完整描述

1 回答

?
繁花如伊

TA貢獻2012條經驗 獲得超12個贊

我正在使用Meteor進行如下更新:


Items.update(Session.get('selectedItem'), {'$set': {'directions.0.name': area.value}})

但是我在努力如何動態設置方向的數組索引,就像這樣:


var index = //a value determined dynamically

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

但這是行不通的。關于如何執行此操作的任何想法?


查看完整回答
反對 回復 2019-12-16
  • 1 回答
  • 0 關注
  • 549 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號