如何删除嵌套集合,例如下面,我想从 Pic 中删除 id 50d3dbce1292dd2e98af1dd2?
数据:
{
"_id": "50d3dbce1292dd2e98af1dd1",
"Name": "Bubba",
"Address": "1111",
"Pic" : [{"_id": "50d3dbce1292dd2e98af1dd2", "Name": "test1.jpg", "Size":"1000"}, {"_id": "50d3dbce1292dd2e98af1dd3",. "Name": "test2.jpg", "Size":"2000"}],
"LastModified": {
"$date": "2012-12-21T03:47:26.535Z"
}
}
用 $pull 解决:
db.coll.update({}, {$pull: {'things': {'myval': 1}}});