Read and write a mongodb database. Fork from node-red-nodes/node-red-node-mongodb
"Official" alternative : https://github.com/node-red/node-red-nodes
Community alternative : https://github.com/ozomer/node-red-contrib-mongodb2
To run this you need a MongoDB server running. For details see the MongoDB site.
Run the following command in your Node-RED user directory - typically
npm install node-red-contrib-mongodb
Nodes to save and retrieve data in a local MongoDB instance.
Optionally, you may also (via a function) set
msg.projectionobject to constrain the returned fields,
You can either set the collection method in the node config or on
Setting it in the node will override
See the MongoDB collection methods docs for examples.
MongoDB only accepts objects.
Find queries a collection using the
msg.payload as the query statement as
per the .find() function.
Count returns a count of the number of documents in a collection or matching a
query using the
msg.payload as the query statement.
Aggregate provides access to the aggregation pipeline using the
msg.payload as the pipeline array.
Save will update an existing object or insert a new object if one does not already exist.
Insert will insert a new object.
Update will modify an existing object or objects. The query to select objects
to update uses
msg.query and the update to the element uses
Update can add an object if it does not exist or update multiple objects.
Remove will remove objects that match the query passed in on
A blank query will delete all of the objects in the collection.
By default MongoDB creates an
msg._id property as the primary key - so
repeated injections of the same
msg will result in many database entries.
If this is NOT the desired behaviour - ie. you want repeated entries to overwrite,
then you must set the
msg._id property to be a constant by the use of a previous function node.
This must be done at the correct level. If only writing msg.payload then payload must contain the _id property.
If writing the whole msg object then it must contain an _id property.
This could be a unique constant or you could create one based on some other msg property.
Currently we do not limit or cap the collection size at all...
The result is returned in