MongoDB/PHP: update individual value of an array
Greetings,
I have the following mongodb object:
{
"_id": ObjectId("4d0b9c7a8b012fe287547157"),
"messages": {
"0": {
"toUname": "Eamorr3",
"fromUname": "Eamorr2",
"time": 1292606586,
"id": "j7zwr2hzx14d3sucmvp5",
"subject": "asdf",
"message": "asdf",
"read": 0
}
},
"uname": "Eamorr3"
}
How do I set "read" to 1 in PHP?
Here's what I've tried sofar to no avail:
upd开发者_JS百科ate(array('uname'=>$uname),array('$set'=>array('messages'=>array('read')=>'1')));
I'm totally stuck. Any help much appreciated.
Many thanks in advance,
I believe it's either
update(array('uname'=>$uname),array('$set'=>array('messages.0'=>array('read')=>'1')));
or
update(array('uname'=>$uname),array('$set'=>array('messages.0.read'=>1));
精彩评论