我在MongoDB(2.4.5)中有以下文档:
{
"_id" : 235399,
"casts" : {
"crew" : [
{
"_id" : 1186343,
"withBase" : true,
"department" : "Directing",
"job" : "Director",
"name" : "Connie Rasinski"
},
{
"_id" : 86342,
"withBase" : true
}
]
},
"likes" : 0,
"rating" : 0,
"rating_count" : 0,
"release_date" : "1955-11-11"
}
我想从casts.crew中的数组元素中删除withBase字段
我尝试了这个:
db.coll.update({_id:235399},{$unset: { "casts.crew.withBase" : 1 } },false,true)
没有任何改变。
我尝试过这个...
db.coll.update({_id:235399},{$unset: { "casts.crew" : { $elemMatch: { "withBase": 1 } } } },false,true)
它从文档中删除了整个团队数组。
有人可以提供正确的查询吗?
updateMany()
。 - mils