Mongo needs update query multiple times


#1

Hi,

perhaps someone has a better understanding of mongo and can explain the following:

Goal was to delete all Attachments saved as base64 unter Attachments.Contetent

db.emails.find({ ‘Attachments.Content’:{$exists:true} }).count()
140

db.emails.update({“Attachments.Content”: {$exists: true}}, {$unset: {“Attachments.$.Content”:true}}, {multi:true})
WriteResult({ “nMatched” : 142, “nUpserted” : 0, “nModified” : 142 })

db.emails.find({ ‘Attachments.Content’:{$exists:true} }).count()
99

db.emails.update({“Attachments.Content”: {$exists: true}}, {$unset: {“Attachments.$.Content”:true}}, {multi:true})
WriteResult({ “nMatched” : 99, “nUpserted” : 0, “nModified” : 99 })

db.emails.find({ ‘Attachments.Content’:{$exists:true} }).count()
81

db.emails.update({“Attachments.Content”: {$exists: true}}, {$unset: {“Attachments.$.Content”:true}}, {multi:true})
WriteResult({ “nMatched” : 81, “nUpserted” : 0, “nModified” : 81 })

db.emails.find({ ‘Attachments.Content’:{$exists:true} }).count()
65

Why do i need to have to run the same query multiple times?

thanks
Benjamin


#2

I would expect this match just 1st item in array