DEV Community

Milan K Jain
Milan K Jain

Posted on

πŸš€ Fixing MongoDB Updates in n8n (No More Workarounds!)

If you've ever used MongoDB with n8n, you've probably hit this limitation.

The MongoDB node in n8n doesn’t actually support real MongoDB update operations.

Yeah… that surprised me too.


😀 The Problem

The existing update functionality is extremely limited:

  • Only allows updating a single field
  • Uses updateKey + value
  • Internally tied to updateOne

That means no support for native MongoDB update operators like:

  • $set (multiple fields)
  • $pull
  • $push
  • $rename
  • $inc

🀯 Real-world limitation

Let’s say you want to remove a value from an array:

{
  "$pull": {
    "tags": "deprecated"
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Not possible in the current node.

Or update multiple fields:

{
  "$set": {
    "status": "active",
    "updatedAt": "2026-01-01"
  }
}
Enter fullscreen mode Exit fullscreen mode

🧠 The Workarounds (that shouldn’t exist)

Because of this, developers are forced to:

  • Use aggregation pipelines 😬
  • Add Code nodes 🀯
  • Chain multiple operations 😡 This defeats the purpose of using a low-code tool like n8n.

πŸ’‘ The Fix

I created a PR that enables JSON-based update operations in the MongoDB node.

βœ… What’s new?

You can now define:

  • A JSON filter
  • A JSON update object πŸ‘‰ Just like native MongoDB.

πŸ”₯ Before vs After

❌ Before

  • One field update only
  • No operators
  • Limited flexibility

βœ… After (JSON Mode)

{
  "filter": {
    "userId": "123"
  },
  "update": {
    "$set": {
      "status": "active"
    },
    "$inc": {
      "loginCount": 1
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Clean
πŸ‘‰ Flexible
πŸ‘‰ Powerful

πŸ› οΈ What this unlocks

This change enables:

  • Updating multiple fields in one operation.
  • Using advanced operators like $pull, $push, $rename.
  • Writing cleaner workflows.
  • Removing unnecessary Code nodes.
  • Aligning with native MongoDB behavior.

βš™οΈ How it works

A new mode is introduced:

  1. Simple Mode (existing)
  2. Uses updateKey
  3. No changes
  4. JSON Mode (new) Accepts raw JSON:
  5. Filter
  6. Update object πŸ‘‰ Fully opt-in πŸ‘‰ No breaking changes

πŸ§ͺ Stability
βœ… Backward compatible
βœ… Input validation (invalid / empty JSON)
βœ… Unit tests added
βœ… All existing tests passing
🎯 Why this matters

n8n is powerful because it bridges the gap between code and no-code.

But limitations like this push developers back into writing code β€” unnecessarily.

This change:

βœ” Reduces friction
βœ” Improves flexibility
βœ” Matches real MongoDB capabilities
βœ” Saves time for developers

πŸš€ PR Link

πŸ‘‰ https://github.com/n8n-io/n8n/pull/27583

Would love feedback from the community and maintainers!

πŸ’¬ Final thought

Sometimes the most impactful improvements aren’t flashy…

They’re the ones that remove everyday friction.

This is one of them.

Top comments (0)