2017-03-03 22 views
0

更新數組的元素我想在監護人更新移動, 該文件是在以下形式的MongoDB如何在一個數組

{ 
    "_id" : ObjectId("575e4d850d61a206084ff035"), 
    "students" : [ 
      { 
        "_id": "58454c8fd01c35cb06ac1d7c", 
        "guardians": [ 
         { 
          _id: "5710b9dbb6744ac07aee6a6d", 
          contact: { 
           mobile: "15800000000" 
          } 
         } 
         ... 
        ] 
      } 
      ... 
     ] 
} 

回答

0
+0

更新基於條件,像這樣 ClassModel.update( \t \t \t \t \t { \t \t \t \t \t \t 'students.guardians._id':用戶id, \t \t \t \t \t \t'status':{$ ne:'deleted'} \t \t \t \t \t}, \t \t \t \t \t { \t \t \t \t \t \t $設置:{ \t \t \t \t \t \t \t '學生$監護人$ contact.mobile':移動 \t \t \t \t \t \t} \t \t \t \t \t}, \t \t \t \t \t {多:真}, \t \t \t \t \t函數(e)中{ \t \t \t \t \t \t下一個(E); \t \t \t \t \t} \t \t \t \t); –