PHP / MongoDB: Dizideki bir değerini güncelleştirmek

0 Cevap php

Ben şu mongodb nesne var:

{
   "_id": ObjectId("4d0b9c7a8b012fe287547157"),
   "messages": {
     "0": {
       "toUname": "Eamorr3",
       "fromUname": "Eamorr2",
       "time": 1292606586,
       "id": "ABCDZZZ",
       "subject": "asdf",
       "message": "asdf",
       "read": 0   //I want to change this to 1!
    },
    "1": {
       "toUname": "Eamorr1",
       "fromUname": "Eamorr3",
       "time": 1292606586,
       "id": "EFGHZZZ",
       "subject": "asdf2",
       "message": "asdf2",
       "read": 0
    }
  },
   "uname": "Eamorr3"
}

Nasıl 1 where id = ABCDZZZZ için "okumak" ayarlarım? Ben PHP kullanıyorum.

Ben aşağıdaki komutu denedim:

$driverInboxes->update(array('uname'=>$uname),array('$set'=>array('messages'=>array('id'=>$id,'read'=>'1'))));

Ben bunu yaptığımda, üzerine yazma oluşur ve alıyorum:

{
   "_id": ObjectId("4d0b9c7a8b012fe287547157"),
   "messages": {
     "id": "j7zwr2hzx14d3sucmvp5",
     "read": "1"
  },
   "uname": "Eamorr3"
}

Tamamen şaşırıp. Herhangi bir yardım çok takdir.

Ben, tüm dizi elemanı çekmek değiştirmek ve ve tekrar içeri itin gerekiyor mu?

Şimdiden çok teşekkürler,

0 Cevap