Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-red-contrib-mongodb4) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-red-contrib-mongodb4
A MongoDB client node for Node-Red powered by MongoDB Driver V4
This package includes two nodes for node-red:
- A configuration node which defines a connection to a MongoDB database server.
- A flow node to execute every MongoDB collection or db operation supported by MongoDB Driver 4.
This node was inspired by other projects like node-red-contrib-mongodb3 or node-red-node-mongodb.
Compatibility
This MongoDB Node is compatible with the following MongoDB Server versions: 6.0, 5.0, 4.4, 4.2, 4.0, 3.6
You will also need a node-red version with NodeJS v12 or v14.
Installation
Navigate to your .node-red directory - typically ~/.node-red.
npm install --save node-red-contrib-mongodb4Usage Example
Import the example flow to get a quick introduction how to use this node.
flow.json

The Configuration Node
Configuration node for MongoDB connection config. This node will create a MongoDB client, with a connection pool for operation nodes.
Simple Connection URI
: Protocol (string) : mongodb or mongodb+srv
: Hostname (string) : Hostname / IP to connect to MongoDB
: Port (number) : Optional port number. In most cases 27017.
Advanced Connection URI
: URI (string) : This will overwrite Protocol, Hostname and Port with your own connection string.
Read the docs: Connection String in URI Format
Authentication
: Username (string) : Username for authentication.
: Password (string) : Password for authentication.
: AuthSource (string) : Specify the database name associated with the user’s credentials.
: AuthMech (string) : Specify the authentication mechanism that MongoDB will use to authenticate the connection.
TLS (optional)
: TLS CA File (path) : Specifies the location of a local .pem file that contains the root certificate chain from the Certificate Authority. This file is used to validate the certificate presented by the mongod/mongos instance.
: TLS Certificate Key File (path) : Specifies the location of a local .pem file that contains either the client's TLS/SSL certificate and key or only the client's TLS/SSL key when tlsCertificateFile is used to provide the certificate.
: TLS Certificate Key Filepassword (string) : Specifies the password to de-crypt the TLS certificate.
: TLS-Insecure (bool) : Disables various certificate validations. THIS IS REALLY NOT SECURE.
More Options
: Options (JSON) : MongoDB Driver 4 MongoClient supports more options. Feel free to overwrite all client options with your own. Read the docs: MongoClientOptions
Database
: Database (string) : A MongoDB database name is required.
Connection Pools
Each configuration node has his own connection pool with a default max poolsize of 100 connection at a given time. More parallel connections / operations will be queued and processed synchronous. In this scenario slow operations will delay fast operations. You can create more separat connection pools with more configuration nodes. More Information
The operation Node
Execute MongoDB collection operations with this node.
Inputs / Options
: Connection (mongodb-client) : Select a MongoDB database server connection.
: Mode | msg.mode (string) : Decide if you want to run a collection or db operation {'collection', 'db'}
: Collection | msg.collection (string) : MongoDB database collection.
: Operation | msg.operation (string) : Run a collection or database operation.
Examples for collection operation are CRUD like find, findOne, insertOne, updateOne, aggregate and many more.
Valid database operations are command, ping, stats and more.
: msg.payload (array) : Pass the CRUD operation arguments as message payload. Message payload has to be array type to pass multiple function arguments to driver operation.
Example: msg.payload = [{name: 'marina'},{fields: {...}}]. The payload array will be passed as function arguments for the MongoDB driver collection operation, like so: collection.find({name: 'marina'}, {fields: {...}})
: Output (string) : For find and aggregate operation. Choose toArray or forEach output type.
: handle document _id (bool) : With this feature enabled, the operation node will convert a document _id of type string to a document _id of type ObjectId.
The default MongoDB document identifier has to be of type ObjectId. This means the native driver expects query arguments like: msg.payload = [{_id: ObjectId("624b527d08e23628e99eb963")}]
This mongodb node can handle this for you. If the string is a valid ObjectId, it will be translated into a real ObjectId before executed by the native driver.
So this will work:
msg.payload = [{_id: "624b527d08e23628e99eb963"}]
...and this will also work:
msg.payload = [{_id: {$in: ["624b527d08e23628e99eb963"]}}]
More information about collection operations
More information here: Collection-API
Payload input
Pass the CRUD operation arguments as message payload.
Message payload has to be array type to pass multiple function arguments to driver operation.
Example: msg.payload = [{name: 'marina'},{fields: {...}}].
The payload array will be passed as function arguments for the MongoDB driver collection operation, like so: collection.find({name: 'marina'}, {fields: {...}})
More information here: Collection-API
Payload Output
The node will output the database driver response as message payload.
The operations aggregate and find can output with toArray or forEach.