Closed wstam88 closed 8 years ago
The db\collection will be placed in msg.payload
, but node-red-contrib-mongodb2 is mostly used for doing operations on mongodb and not for fetching the db instance.
In order to do a specific operation, pass its arguments in an array in the input message payload. For example, try calling msg.payload = [{_id:'x'},{fields:{myfield:1}}];
in a function node that is wired to a node-red-contrib-mongodb2 node with a findOne
operation.
Thank you for your answer, however I find that your example doesn't work for me. It is my understanding that in order to find documents by there ID it has to be something like this: '{"_id": ObjectId(ID)}'. So, the ID field is special in MongoDB unless it was set by hand. It does however work for other fields.
The examples on http://flows.nodered.org do not query based on a MongoDB generated _id which stores itself with a type of 'ObjectID'.
Any suggestions?
Hi,
In my server I added mongodb: require('mongodb')
to the red_settings' functionGlobalContext
.
Then I can use global.get('mongodb').ObjectId(...)
in any function node.
Thank you, that seems like a great solution.
Hi,
I'm having trouble to get the DB or collection instance; when I select the db or collection from the list where does it go? How can I get access to it?
Thanks,
Wesley