MongoDB Unset

Unset a field from Documents

Sample of document, and you want to unset the field “affLink”.

domain.json

{ "_id" : 1,

"domain" : "mkyong.com",

"affLink" : "abc" }

Interested in mastering Mongo DB Training?

Enroll now for FREE demo on Mongo DB Training.

To unset a field from all documents, set {multi: true}, else only the field of the first matched document will be removed.

db.domain.update({},{$unset: {affLink:1}},{multi: true});

Output

domain.json

{ "_id" : 1, "domain" : "mkyong.com" }

For indepth understanding click on