Registry / database / node-red-contrib-mongodb4

node-red-contrib-mongodb4

JSON →
library3.4.0jsnpmunverified

A Node-RED node that wraps the native MongoDB Node.js driver (v6) for database operations without limitations. Version 3.4.0 is current stable. Released on npm with monthly cadence. Unlike other Node-RED MongoDB nodes, this exposes full driver API via a flow node, supporting all CRUD, aggregation, and admin operations. Requires Node-RED >=3.0.0 and Node.js >=16.20.1. Compatible with MongoDB server versions 4.0-8.0.

npm install node-red-contrib-mongodb4
INSTALL
IMPORT
SIG · NODE-RED-CONTRIB-M
N
node-red-contrib-mongodb4
databasejavascriptv3.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Node-RED node types (mongodb-config and mongodb-flow)
✓ Install package via npm in .node-red directory; nodes appear in palette automatically
✗ Manual require or import in Node-RED function nodes
These are Node-RED nodes, not standard JS modules. They are loaded by Node-RED runtime from the package's nodes directory.

Demonstrates how to pass operation arguments via msg.payload array in Node-RED flow node.

// Example: Insert one document into a MongoDB collection using the flow node // Set operation to 'insertOne' and provide payload as an array: msg.payload = [{ name: 'Anna', age: 25 }]; return msg; // Example: Find documents with query and options const query = { age: { $gte: 18 } }; const options = { sort: { name: 1 }, limit: 5 }; msg.payload = [query, options]; return msg; // Example: Aggregate pipeline const pipeline = [ { $match: { age: { $gte: 18 } } }, { $group: { _id: '$city', count: { $sum: 1 } } } ]; msg.payload = [pipeline]; return msg;
Debug
Known issues
breakingVersion 3.x uses MongoDB driver v6 which includes breaking changes from driver v5. For example, MongoClient constructor no longer accepts callback; only use new MongoClient(url).
fix
Review the official MongoDB Node.js driver v6 upgrade guide: https://www.mongodb.com/docs/drivers/node/current/upgrade/#version-6.0-breaking-changes
affects: >=3.0.0
gotchaThe operation argument must be passed as an array inside msg.payload, even for a single argument like insertOne. Forgetting the array wrapper leads to incorrect function call.
fix
Always wrap arguments in an array: msg.payload = [document] not msg.payload = document.
affects: all
gotchaWhen using aggregation, the pipeline is itself an array, so msg.payload must be an array containing that array: msg.payload = [pipeline];
fix
Use msg.payload = [pipeline];
affects: all
deprecatedThe field 'msg.payload' is used for operation arguments; this overrides the standard Node-RED pattern where msg.payload is the main data. The node expects a very specific payload structure.
fix
Always set msg.payload to an array of arguments for the MongoDB driver method.
affects: all
Errors
Common errors & fixes
MongoError: cannot use non-array argument with aggregate
Passed pipeline directly as msg.payload instead of wrapping it in an array.
fix
Change msg.payload = pipeline; to msg.payload = [pipeline];
MongoError: (Unauthorized) Authentication failed
Invalid username/password or wrong authSource.
fix
Verify credentials and ensure authSource matches the database where the user is defined.
MongoError: connect ECONNREFUSED
MongoDB server is not reachable at the given host/port.
fix
Check network connectivity and MongoDB server status; verify host/port in config node.
TypeError: client.db is not a function
The config node failed to establish a connection, so the client is undefined or not properly initialized.
fix
Check connection settings and ensure the config node shows connected status in the editor.
Upgrade
Version history
3.4.0latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver v6.12 used for all database operations
Agent activity
7 hits · last 30 days
node
6
Resources
node-red-contrib-mongodb4 — npm install node-red-contrib-mongodb4 · libregistry