2014-02-14 151 views
0

我需要更新的子嵌套文檔中的第n個元素的第n個元素:我有這樣的結構:更新子嵌套文檔的MongoDB

{ 
    "_id" : ObjectId("52fdbbb470c68c3c14d60700"), 
    "curations" : [{ 

     "measurements" : 
     [ 
     { 
      "_id" : ObjectId("52fdbbb470c68c3c14d80700"), 
      "name" : "GSM15729", 
      "Vals" : ["N/A", "bronchus, lung", "bronchial epithelial cell", "N/A", "N/A", "N/A", "non-smoker", "GPL96"] 
     }, 
     { 
      "_id" : ObjectId("52fdbbb470c68c3c14d90700"), 
      "name" : "GSM104072", 
      "Vals" : ["N/A", "bronchus, lung", "bronchial epithelial cell", "N/A", "N/A", "N/A", "current smoker", "GPL96"] 
     } 

     ] 

    }] 
} 

而且我想更新例如第四屆「N/A「(第5位),在最後一個子陣列‘

我用命令行嘗試這種代碼,但它似乎並沒有被工作

db.Series.find({"curations.measurements._id":new ObjectId("52fdbbb470c68c3c14d90700")}, 
    { $set: { 
     "curations.measurements.$.Vals.4": "new_value" 
     } 
}); 

感謝您的幫助丘壑’!

回答

0

最後我發現錯誤,只是我忘了零...(陣列)

db.Series.find({"curations.0.measurements._id":new ObjectId("52fdbbb470c68c3c14d90700")}, 
    { $set: { 
     "curations.0.measurements.$.Vals.4": "new_value" <=In this line 
     } 
});