mongodb-ex

Extended MongoDB node with authentic MongoDB query syntax, advanced update operators, update pipelines, arrayFilters, bulk operations, type coercion and more.

Package Information

Downloads: 2 weeklyĀ /Ā 32 monthly
Latest Version: 0.1.3
Author: Bobby Kotzev

Documentation

n8n šŸ¤ n8n
n8n node MongoDb Ex (tended)

n8n-nodes-mongodb-ex

An extended n8n MongoDB node, tailor-made for native MongoDB developers. This node goes beyond the built-in MongoDB node by providing authentic MongoDB query syntax, advanced update operators, update pipelines, arrayFilters, bulk operations, type coercion and more.

Table of Contents

Overview

MongoDB Extended (MongoDbEx) is a drop-in replacement for n8n’s base MongoDB node with a richer, MongoDB-native developer experience:

  • Use real MongoDB query syntax and aggregation pipelines
  • Leverage advanced update operators and update pipelines
  • Target array elements precisely with arrayFilters and positional operators
  • Perform single or bulk operations (insertMany/updateMany/bulkWrite)
  • Automatic type coercion for ObjectId and ISO dates
  • Subnode support - use it as a tool for AI Agents

Installation

Follow the community nodes installation guide, then search for and install n8n-nodes-mongodb-ex.

Alternatively, install directly:

npm install n8n-nodes-mongodb-ex

For Docker-based deployments, add to your n8n Docker image:

RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-mongodb-ex

Features

  • MongoDB-native queries and pipelines
  • Advanced update operators: $set, $unset, $inc, $push, $pull, etc.
  • Update pipelines supported (array of stages)
  • Array element targeting with arrayFilters
  • Bulk operations: insertMany, updateMany, bulkWrite
  • JSON input for queries, documents, updates
  • Automatic type coercion of 24-hex ObjectId strings and ISO date strings
  • Upsert support for updates

Operations

  • Aggregate: Run full MongoDB aggregation pipelines
  • Find: Query documents using native MongoDB operators
  • Insert: Insert one or many documents
  • Update: Update one or many documents with operators or update pipelines
  • FindOneAndUpdate: Atomic find-and-update with full MongoDB update support
  • FindOneAndReplace: Atomic find-and-replace
  • Delete: Delete by native MongoDB filter

Type Coercion

ObjectId and Date values are automatically handled through and through.

Input

{
  "_id": "507f1f77bcf86cd799439011",
  "name": "John Doe",
  "orders": [
    {
      "productId": "66d6215f9b3c4a18e0f7a2c1",
      "quantity": 2,
      "timestamp": "2025-02-03T18:46:00Z"
    }
  ],
  "createdAt": "2024-01-15T10:44:00Z"
}

Saved DB Document

{
  "_id": ObjectId("507f1f77bcf86cd799439011"),
  "name": "John Doe",
   "orders": [
    {
      "productId": ObjectId("66d6215f9b3c4a18e0f7a2c1"),
      "quantity": 2,
      "timestamp": ISODate("2025-02-03T18:46:00Z")
    }
  ],
  "createdAt": ISODate("2024-01-15T10:44:00Z")
}

$oid and $toDate operators in pipelines are recognized and respected. Any manual type conversions you may already have in place will not be overwritten.

Usage Examples

šŸ“‘ Advanced Update with arrayFilters

Filter:

{ "_id": 12345 }

Update:

{
  "$set": {
    "orders.$[elem].status": "shipped",
    "orders.$[elem].shippedAt": "2024-01-15T10:00:00Z"
  }
}

arrayFilters:

  [{"elem.status": "pending"}]

šŸ“œ Update Pipeline

Filter:

{
  "_id": {
    "type": "counter",
    "metric": "orders_summary"
  } 
}

Update (pipeline):

[
  {
    "$set": {
      "totalSpent": {"$add": ["$totalSpent", "$currentOrder.amount"]},
      "lastOrderDate": "$$NOW",
      "orderCount": {"$add": ["$orderCount", 1]}
    }
  },
  {
    "$push": {
      "logs": { "message": "Stats updated", "timestamp": "$$NOW" }
    } 
  }
]

ā¬ Aggregation (pipeline):

[
  {
    "$match": {"status": "active"}
  },
  {
    "$lookup": {
      "from": "orders",
      "localField": "_id",
      "foreignField": "userId",
      "as": "userOrders"
    }
  },
  {
    "$group": {
      "_id": "$department",
      "totalOrders": {"$sum": {"$size": "$userOrders"}},
      "avgOrderValue": {"$avg": "$userOrders.total"}
    }
  }
]

šŸ›’ Bulk Insert with Type Coercion

Executes a single updateMany call for all inputs.

Input:

{
  [
    {
      "_id": "507f1f77bcf86cd799439011",
      "createdAt": "2024-01-15T10:00:00Z",
      "name": "John Doe"
    },
    {
      "_id": "507f1f77bcf86cd799439012",
      "createdAt": "2024-01-15T11:00:00Z",
      "name": "Jane Smith"
    }
  ]
}

Many:

Set to true


🚚 Bulk Write

This operation expects each input to already of valid MongoDB bulk operation shape (insertOne, updateOne, updateMany, deleteOne, deleteMany, replaceOne). See documentation

Input:

{
  [
    {
      "updateOne": {
        "filter": { "_id": "507f1f77bcf86cd799439011" },
        "update": { 
          "$set": { "name.last": "Doe" },
          "$currentDate": { "timestamp": true }
        }
      }
    },
    {
      "updateOne": {
        "filter": { "_id": "507f1f77bcf86cd799439013" },
        "update": {
          "$set": { "active": false }
          "$currentDate": { "timestamp": true }
        }
      }
    }
  ]
}

Compatibility

  • n8n >= 0.187.0
  • Node.js >= 20.15
  • MongoDB >= 4.4

License

MIT

Discussion