2016-11-16 45 views

回答

2

您需要$使用推

如果(_id_exists):

 newAdrz = {"$push": {"addresses": 
          { 
           street: "1 Some Other Street", 
           city: "Boston", 
           state: "MA", 
           zip: "12345" 
          }} 
        } 

     self.collection.update({_id: "joe"}, newAdrz) 

其他:

 root = {_id: "joe",name: "Joe Bookreader", 
      addresses: [ 
      { 
       street: "123 Fake Street", 
       city: "Faketon", 
       state: "MA", 
       zip: "12345" 
      }] 
       } 

      self.collection.insert(root) 

如果_id已經在存在這將更新地址陣列mongodb

相關問題