我有以下文件:
{
"_id" : "2646953848367646922",
"arr1" : [
{
"n" : 1,
"name" : "2646953848367646922"
},
{
"n" : 0.75,
"name" : "7750833069621794130"
}
],
"arr2" : [
{
"n" : 1,
"name" : "2646953848367646922"
},
{
"n" : 0.75,
"name" : "7750833069621794130"
}
]
}
我可以只使用一个查询从两个嵌套数组中删除元素吗?
答案 0 :(得分:2)
使用$pull
。在shell中:
db.test.update({_id: "2646953848367646922"}, {$pull: {
arr1: {name: "7750833069621794130"},
arr2: {name: "2646953848367646922"}
}})