How to remove a field completely from a MongoDB document ?
How to remove a field completely from a MongoDB document ?
just try to do this below code:
db.example.update({}, {$unset: {words:1}}, false, true);
further information http://www.mongodb.org/display/DOCS/Updating#Updating-%24unset
UPDATING:
For the link https://docs.mongodb.com/manual/reference/operator/update/unset/no longer covers ‘$unset’ing. Be sure to add {multi: true} if you want to delete this field from entire of the documents in the collection; or else, it will only delete it from the first document it search that matches. See this for updated documentation:
Specimen:
db.example.update({}, {$unset: {words:1}} , {multi: true});
To delete field in MongoDB:
The lonely record:
db.getCollection('userData').update({}, {$unset: {pi: 1}})
The many record:
db.getCollection('userData').update({}, {$unset: {pi: 1}}, {multi: true})
you can also just try to do this one:
db.example.updateMany({},{"$unset":{"tags.words":1}})