2017-06-27 126 views
0

如何使用yii2更新名爲TEST1的成員年齡。
用下面的代碼來更新,但我指定了那裏的索引,我想用out來指定索引。用戶:: updateAll(['$ set'=> ['Addresses.0.members.0.age'=> 100]],['IN','Addresses.members.name',[' TEST1']]);yii2 mongodb更新嵌入式陣列

{ 
    "_id" : ObjectId("595209b65312f48195fb2e01"), 
    "username" : "Test name", 
    "Addresses" : [ 
      { 
        "address_no" : 1, 
        "Address" : "Test house", 
        "City" : "test city", 
        "State" : "Test state", 
        "Mobile" : "9999999", 
        "members" : [ 
          { 
            "name" : "TEST1", 
            "age" : 35 
          }, 
          { 
            "name" : "TEST2", 
            "age" : 30 
          }, 
        ] 
      }, 
      { 
        "address_no" : 2, 
        "Address" : "2B, Test place", 
        "City" : "Test city", 
        "State" : "Test State", 
        "Pincode" : "12345", 
        "Phone" : "1234568789", 
        "Mobile" : 9999999999 
      } 
    ], 
    "Beneficiaries" : [ 
      { 
        "beneficiary_id" : 1, 
        "Name" : "Test1", 
        "Age" : "28", 
        "Sex" : "F" 
      } 
    ], 
    "auth_key" : "esd8d89ds89ds89ds89ds", 

}

回答