Logo
BlogToast.
HomeAll PostsCategoriesRandom
Sign in
Logo
BlogToast.

Discover stories, insights, and perspectives from writers around the world.

Explore

  • All posts
  • Categories
  • Random

Dashboard

  • Sign in
  • Sign up
  • Forgot password

Legal

  • Contact
  • Privacy policy
  • Terms of service

© 2026 BlogToast. All rights reserved.

How to Remove a Field from All Documents in MongoDB Using Atlas Aggregation
Tutorials3 min read

How to Remove a Field from All Documents in MongoDB Using Atlas Aggregation

N

N@rutO

June 17, 2025

When working with MongoDB, sometimes you might accidentally merge unwanted data into a collection — like an extra field that doesn't belong. If you're using MongoDB Atlas, it's entirely possible to clean up your documents using the Aggregation Pipeline, no backend code required.

Let’s walk through removing a field (like blogs) from all documents using just the MongoDB Atlas UI.


🔥 The Problem

You accidentally ran a $merge operation that added a blogs field to every document in your files collection. Now you want to remove that field from every document — without touching the backend.


🧰 Tools Used

  • MongoDB Atlas

  • Aggregation Pipeline Builder

  • No code or shell required!


✅ Step-by-Step: Remove a Field Using Aggregation


🟨 Step 1: Go to Aggregations

  1. Open your Atlas project.

  2. Navigate to your files collection.

  3. Click on the "Aggregations" tab.


🟩 Step 2: Add $unset Stage

This stage removes the field from the documents in the pipeline result.

{
  "$unset": "blogs"
}

This will immediately show a preview of your documents without the blogs field.

✅ Important: Don’t include a $match stage unless you want to only update certain documents.


🟥 Step 3: Add $merge Stage

This is the step that actually applies the change to the database.

Use this configuration:

{
  "into": "files",
  "whenMatched": "replace",
  "whenNotMatched": "discard"
}

✅ Why replace and not merge?

  • "merge" preserves untouched fields from the original document — meaning removed fields can sneak back in.

  • "replace" fully overwrites each document with the cleaned-up version — ensuring removed fields stay gone.


▶️ Step 4: Click “Run”

Once your pipeline is ready, the “Run” button should appear. Click it to process and update all documents.


🧪 Final Check

To make sure the cleanup worked:

  1. Go back to your Documents tab.

  2. Run a filter:

    { "blogs": { "$exists": true } }

✅ If nothing shows up — your cleanup worked!

🧵 Conclusion

Removing a field from all MongoDB documents is easy and safe using the Aggregation Pipeline in Atlas. Just remember:

  • Use $unset to drop the field.

  • Use $merge with "whenMatched": "replace" to fully apply the change.

No shell. No code. Just clicks.

Tags

MongoDB remove field MongoDB Atlas aggregation MongoDB unset field MongoDB updateMany MongoDB merge replace MongoDB field removal MongoDB data cleanup MongoDB Atlas tutorial
Advertisement

Discussion (0)

Related Blogs

Explore similar articles

How to setup weak password in Ubuntu
Tutorials
2 min

How to setup weak password in Ubuntu

J

N@rutO

Sep 11

2 0
Fix files being tracked even after adding to gitignore
Tutorials
2 min

Fix files being tracked even after adding to gitignore

J

N@rutO

Sep 18

8 0