MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Remove field from entire collection

Hello everyone

Is there any command I can use to remove a field from MongoDB entire collection?

I used the $unset aggregation command but it does not remove from the entire collection at once.

Sincerely
Ezequias Rocha

Hi! You can use:

db.coll.updateMany(
  {}, 
  {
    $unset: {"yourField": ""}
  }
)
3 Likes