0.2.4 • Published 4 years ago

node-red-contrib-mongo-client v0.2.4

Weekly downloads
15
License
MIT
Repository
github
Last release
4 years ago

node-red-contrib-mongo-client

MongoDB client for Node-RED

install

npm i node-red-contrib-mongo-client -S

Usage

Please refer to the mongoDB node driver 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
    callback: function(_msg, _nextNode){
        // _msg: OUTPUT object
        // _nextNode: the MongoClient node
    }
}


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

    // Any addition value from INPUT...
    payload,
    foo,
    ...
}

function node

const { ObjectId, db, collection } = msg

collection
    .countDocuments()
    .then( payload => node.send({ payload }) )
    .catch( node.error )

db.collection('collectionName')
    .find({
        _id: ObjectId('5d2d8fba4e15c14483a71500')
    })
    .limit(100)
    .sort({ timestamp: -1 })
    .toArray()
    .then( payload => node.send({ payload }) )
    .catch( node.error )
0.2.4

4 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago