
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
node-red-contrib-mongodb4
Advanced tools
A MongoDB driver node for Node-Red without limitations.
This package includes two nodes for node-red:
The Config Node
Connect to your local MongoDB Server or a MongoDB Atlas cluster.
The Flow Node
Execute a database or collection operation within your flow. This node was developed to use all the features of the native MongoDB driver without any limitations.
This node was inspired by other projects like node-red-contrib-mongodb3 or node-red-node-mongodb.
Navigate to your .node-red directory - typically ~/.node-red
.
npm install --save --omit=dev node-red-contrib-mongodb4
The latest version of node-red-contrib-mongodb4@2.4.x is compatible with the following MongoDB server versions: 8.0, 7.0, 6.0, 5.0, 4.4, 4.2, 4.0
Node-RED >= v3.0.0
NodeJS >= v16.20.1
Version 3.x of this node-red node is now using the mongodb driver version 6.12.
These breaking changes could affect you if you upgrade from node-red-contrib-mongodb4@2.x.x to node-red-contrib-mongodb@3.x.x. Read here
Import the example flow to get a quick introduction how to use this node.
flow.json
Configuration node for MongoDB connection config. This node will create a MongoDB client, with a connection pool for operation nodes.
Protocol - mongodb
or mongodb+srv
Hostname - Hostname / IP to connect to MongoDB
Port - Optional port number. In most cases 27017
.
Username - Username for authentication.
Password - Password for authentication.
AuthMech - Specify the authentication mechanism that MongoDB will use to authenticate the connection. This will only be used in combination with username and password.
AuthSource - Specify the database name associated with the user’s credentials.
Database - A MongoDB database name is required.
Application Name - The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections.
If this field is unspecified, the client node will create a app name for you.
That looks like this: nodered-azmr5z97
. The prefix nodered
is static. azmr5z97
is a random connection pool id, created on runtime start-up, config-node update and full deployment.
The current app name of a config node is logged to the node-red runtime log.
Check the current db connections with this query:
db.currentOp(true).inprog.reduce((accumulator, connection) => {
const appName = connection.appName || "unknown";
accumulator[appName] = (accumulator[appName] || 0) + 1;
accumulator.totalCount ++;
return accumulator;
}, {totalCount: 0})
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 - Disables various certificate validations. THIS IS REALLY NOT SECURE.
ConnectTimeoutMS - Specifies the amount of time, in milliseconds, to wait to establish a single TCP socket connection to the server before raising an error.
SocketTimeoutMS - To make sure that the driver correctly closes the socket in these cases, set the SocketTimeoutMS option. When a MongoDB process times out, the driver will close the socket. We recommend that you select a value for socketTimeoutMS that is two to three times as long as the expected duration of the slowest operation that your application executes.
If you set the value of ConnectTimeoutMS or SocketTimeoutMS to 0, your application will use the operating system's default socket timeout value.
MinPoolSize / MaxPoolsize - Specifies the minimun and maximum number of connections the driver should create in its connection pool. This count includes connections in use.
MaxIdleTimeMS - Specifies the amount of time, in milliseconds, a connection can be idle before it's closed. Specifying 0 means no minimum.
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
Execute MongoDB collection operations with this node.
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.
Common collection operations are find
, findOne
, insertOne
, insertMany
, updateOne
, updateMany
, deleteOne
, deleteMany
, aggregate
and more.
insert
, update
and delete
are deprecated and not supported by the latest mongodb driver version. Read the upgrade instructions for more information.
Common database operations are command
, ping
, stats
and more.
Example insertOne
:
msg.payload = [{name: 'Anna', age: 1}];
Example find
:
// find query argument
const query = {
age: 22
};
// find option argument
const options = {
sort: {name: 1},
projection: {name: 1},
limit: 10,
skip: 2
};
// payload for mongodb4 node
msg.payload = [query, options];
return msg;
The payload array will be passed as function arguments for the MongoDB driver collection operation
: collection.find({age: 22}, {sort: {...}})
Another example for an aggregation call:
// aggregation pipeline
const pipeline = [{
$sort:{age: 1}
}, {
$project: {
name: 1
}
},{
$limit: 10
}];
// optional: aggregate options
const options = {
allowDiskUse: true
};
// payload for mongodb4 node
msg.payload = [pipeline, options];
return msg;
In a simple aggregation call you have an array inside array like msg.payload = [pipeline]
. This might be confusing, but I haven't found a better solution for that.
Output - For find
and aggregate
operation. Choose toArray
or forEach
output type.
MaxTimeMS - MaxTimeMS Specifies the maximum amount of time the server should wait for an operation to complete after it has reached the server. If an operation runs over the specified time limit, it returns a timeout error. Prevent long-running operations from slowing down the server by specifying a timeout value. Specifying 0 means no timeout.
Handle document _id (deprecated) - With this feature enabled, the operation node will search for _id fields of type string to convert them into document _id of type ObjectId. Be aware that not every _id field has to be a ObjectId field. Use this feature only if necessary. A better solution is to use explicit BSON types in your query (Read: How to use BSON Types).
The default MongoDB document identifier has to be of type ObjectId. This means the native driver expects query arguments like: msg.payload = [{_id: new 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"]}}]
The node will output the database driver response as message payload.
The operations aggregate
and find
can output with toArray
or forEach
.
You can use BSON types with this node.
First enable "mongodb" in your function global context. Add this to your settings.js
file - typically this file located in ~/.node-red
:
functionGlobalContext: {
mongodb: require("node-red-contrib-mongodb4/node_modules/mongodb")
},
This kind of require statement ensures that we use the BSON types from the mongodb driver used in this node. Otherwise we could run into compatibilty issues.
You can now use BSON types in your function node like so:
// get BSON types
const {ObjectId, Double, Timestamp} = global.get("mongodb");
// write your query
msg.payload = [{
_id: new ObjectId() ,
value: new Double(1.4),
ts: new Timestamp()
}];
// send them to the mongodb node
return msg;
Node status information is displayed below the node:
FAQs
A MongoDB node for Node-Red without limitations.
The npm package node-red-contrib-mongodb4 receives a total of 442 weekly downloads. As such, node-red-contrib-mongodb4 popularity was classified as not popular.
We found that node-red-contrib-mongodb4 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.