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

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.