0

hello guys i got this collection with this schema

{
        "_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
}

i want to delete the key HighFrequency in the array of documents hobbies
i used this query but no modified count is found

> db.persoms.updateMany({hobbies:{$elemMatch : {frequency:{$gt:2}}}},{$unset : {
HighFrequency:""}})
{ "acknowledged" : true, "matchedCount" : 5, "modifiedCount" : 0 }
>

can you guys determine where is the issue

1 Answers1

1

db.persoms.updateMany({
   "hobbies.frequency": { $gt: 2 }
},{
   $unset: {
      "hobbies.$.HighFrequency": true
   }
}, false, true)

I believe this can help you to achieve what you want.

Nicolae Maties
  • 2,476
  • 1
  • 16
  • 26