大家好,我以这种模式获得了这个收藏
{
"_id" : ObjectId("5e2f5dd42b3d86c0caa06641"),
"name" : "Manuel",
"hobbies" : [
{
"title" : "Cooking",
"frequency" : 5,
"highFrequency" : true,
"HighFrequency" : true
},
{
"title" : "Cars",
"frequency" : 2,
"HighFrequency" : true
}
],
"TotalAge" : 31
}
{
"_id" : ObjectId("5e2f5dd42b3d86c0caa06642"),
"name" : "Chris",
"hobbies" : [
{
"title" : "balling",
"frequency" : 2,
"HighFrequency" : true
},
{
"title" : "hacking",
"frequency" : 5,
"highFrequency" : true,
"HighFrequency" : true
}
],
"TotalAge" : 35
}
我要删除文档兴趣爱好
中的键高频
我使用了此查询,但未找到修改的计数
> db.persoms.updateMany({hobbies:{$elemMatch : {frequency:{$gt:2}}}},{$unset : {
HighFrequency:""}})
{ "acknowledged" : true, "matchedCount" : 5, "modifiedCount" : 0 }
>
你们能确定问题出在哪里
答案 0 :(得分:1)
db.persoms.updateMany({
"hobbies.frequency": { $gt: 2 }
},{
$unset: {
"hobbies.$.HighFrequency": true
}
}, false, true)
我相信这可以帮助您实现所需的目标。