ozomer / node-red-contrib-mongodb2

MongoDB driver node for Node-RED
Apache License 2.0
15 stars 19 forks source link

MongoDB generated ID #38

Open pelagaggi opened 5 years ago

pelagaggi commented 5 years ago

Hello, I am using node-red-contrib-monggodb3 and having troubles to pass an ObjectId as an argument, not being able to use a MongoDB auto-generated _id, is there any way to use "_id": 'ObjectId("myID")' as an argument? I.E I have the following document in my collection:

{
    "_id" : ObjectId("5c9156c7f8c3ec3259454571"),
    "name" : "teste_site_1",
}

If I pass as msg.payload to findOne Operation

msg.payload = {"name":"teste_site_1"}

returns my document without ObjectID in _id

{
    "_id" : "5c9156c7f8c3ec3259454571",
    "name" : "teste_site_1",
}

if I pass the _id as agument:

msg.payload = {"name":"teste_site_1"}

returns empty. I can not call ObjectId in node-red and also cannot pass as string ObjectId.

Is this a bug or am I missing something?

pelagaggi commented 5 years ago

I have found a workaround and left in stackoverflow.

Not sure if this is the correct way of dealing with the issue.