Mongo update/remove multiple fields

To remove fields from documents in a collection use:


Or, if you want to add new fields, use set:

db.test.update({data:{$exists:false}},{$set:{data:"your value"}},{multi:1});

Set “multi” to 1 if you want to update/remove fields in all documents that match the criteria.

2 thoughts on “Mongo update/remove multiple fields

  1. kocka

    Isn’t this removing a single field from multiple documents rather than removing multiple fields from a single document?

Leave a Reply to Tanya Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s