以下是mongodb
中的内容,如下所示:
{
"_id": 74924,
"bangs": {
"436": {
"join_time": 1345624851,
"status": 1,
"scores": 0
},
"446": {
"join_time": 1355727257,
"status": 1,
"scores": 0
}
},
"_id": 74926,
"bangs": {
"436": {
"join_time": 1345624851,
"status": 1,
"scores": 0
},
"446": {
"join_time": 1355727257,
"status": 1,
"scores": 0
}
}
}
我想删除:
"436": {
"join_time": 1345624851,
"status": 1,
"scores": 0
},
where _id=74924
结果将是:
{
"_id": 74924,
"bangs": {
"446": {
"join_time": 1355727257,
"status": 1,
"scores": 0
}
},
"_id": 74926,
"bangs": {
"436": {
"join_time": 1345624851,
"status": 1,
"scores": 0
},
"446": {
"join_time": 1355727257,
"status": 1,
"scores": 0
}
}
}
我写了这样的代码:
$mongo->users->users->update(array('_id'=>74924), array('$pull'=>array('bangs'=>436)));
但记录没有删除
我该如何编写代码?
提前谢谢!
答案 0 :(得分:1)
你可以用它删除它:
db.test.update( { _id:74924 }, { $unset: {"bangs.436":1} } )
// I think this can be written in php like this:
$mongo->users->users->update(array('_id'=>74924), array('$unset'=>array('bangs.436'=>1)));