Reputation: 2821
How to delete a fields from documents that meet some criteria? For exmaple, I inserted in mongodb command line documents:
db.test1.insert({LISTID: 52, 259: 180})
db.test1.insert({LISTID: 52, 259: 185})
Then I try to delete fields "259" for all documents with LISTID: 52:
db.test1.update({LISTID: 52}, {$unset: {"259" : 1}})
I looks like it delete fields "259" only for first document, but doesn't delete for the last.
Upvotes: 0
Views: 78
Reputation: 18595
You have to set the multiple flag to true :
db.test1.update({LISTID: 52}, {$unset: {"259" : 1}}, false, true)
By default MongoDB only updates the first document that matches the criteria.
Upvotes: 4