node-red-contrib-mongo-client 0.2.2

A mongodb client for Node-Red

npm install node-red-contrib-mongo-client

node-red-contrib-mongo-client

MongoDB client for Node-RED

Usage

Please refer to the mongoDB node driver 'Collection' documentation to read about each operation.

// input
{
    // Any INPUT will be passed to OUTPUT
    payload,
    foo,
    ...
    // If require MongoDb's functions
    require:['ObjectId','MongoError']
    // callback function
    function(_msg, next){
        // _msg: OUTPUT object
        // next: the MongoClient node
    }
}


// OUTPUT object
{
    // Any 'require' functions from INPUT can be accessed by: `db.ObjectId(...)`
    db,
    // If the 'collectionName' is provided:
    collection

    // From INPUT
    payload,
    foo,
    ...
}

function node

msg.collection
    .countDocuments()
    .then( r => node.send({ payload:r }) )

const ObjectId = msg.ObjectId
msg.db.collection('collectionName')
    .find({
        _id: ObjectId('5d2d8fba4e15c14483a71500')
    })
    .toArray()
    .then( r => node.send({ payload:r }) )

Node Info

Version: 0.2.2
Updated 6 years, 3 months ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

11 in the last week

Nodes

  • mongo-client
  • mongo-client in

Keywords

  • node-red
  • mongodb

Maintainers