更新值我有以下mongodb的对象:PHP/MongoDB的:在一个阵列
{
"_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"
}
如何设置 “读出” 1其中id = ABCDZZZZ?我使用PHP。
我试过下面的命令:
$driverInboxes->update(array('uname'=>$uname),array('$set'=>array('messages'=>array('id'=>$id,'read'=>'1'))));
但是当我这样做,覆盖发生,我也得到:
{
"_id": ObjectId("4d0b9c7a8b012fe287547157"),
"messages": {
"id": "j7zwr2hzx14d3sucmvp5",
"read": "1"
},
"uname": "Eamorr3"
}
我完全卡住。任何帮助非常感谢。
我是否需要拉动整个数组元素,修改并将其重新推回?
提前许多感谢,
[MongoDB更新嵌套数组]可能的重复(http://stackoverflow.com/questions/11261521/mongodb-update-nested-array) – user956584 2015-07-14 17:10:08
其实现在它的可能性:http://stackoverflow.com/questions/ 11261521/mongodb-update-nested-array – user956584 2015-07-14 17:10:55