我有一个像
这样的JSON文档{
"branch": [
{
"section": [
{
"sub": "edc",
"time": "one hour",
"frequency": "3"
},
{
"sub": "bee",
"time": "two hours",
"frequency": "4"
}
]
},
{
"section": [
{
"sub": "ss",
"time": "one hour",
"frequency": "2"
},
{
"sub": "ms",
"time": "two hours",
"frequency": "5"
}
]
}
]
}
现在我要删除
{
"sub": "edc",
"time": "one hour",
"frequency": "3"
}
使用以下集合中的"sub":"edc"
我希望查询在mongo db中执行更改
答案 0 :(得分:2)
你需要使用$pull
,虽然我没有使用嵌套数组。
请参阅http://docs.mongodb.org/manual/reference/operator/pull/
类似的东西:(但你需要测试它)
db.yourcoll.update( { "branch.section.sub": 'edu' }, { $pull: { "branch.section.sub": 'edu' } } )
这是一个类似的问题:
How to remove an element from a doubly-nested array in a MongoDB document