FindOne on node mongodb-2 to no avail

I'm trying to use the mongodb-2 node to retrieve a saved information and for that I'm using the example of the mongodb-2 node page but without success...

In the terminal the query returns me the desired information as shown in the print below:

image

This is the flow I'm following as a model:

[{"id":"68165b4c.c9e594","type":"function","z":"78f389d4.a3e498","name":"findOne","func":" var newMsg = {};\nnewMsg.operation  = 'findOne';\nnewMsg.payload    = { 'name' : 'Pete1' , 'names' : 'Pete2' };\nnewMsg.projection = { 'name' : 1 , '_id' : 0 };\nreturn newMsg;","outputs":1,"x":332,"y":220,"wires":[["a5eff45.9a49908"]]}]

This is what I'm trying to use to retrieve the information:

[{"id":"528be7f.6a30d18","type":"function","z":"ca7a266a.c18118","name":"findOne","func":" var newMsg = {};\nnewMsg.operation  = 'findOne';\nnewMsg.payload    = { 'timestamp' : '/28\\/08\\/2021/' };\n//newMsg.projection = { 'timestamp' : 1 };\nreturn newMsg;","outputs":1,"noerr":0,"x":760,"y":240,"wires":[["3f71662.230999a"]]}]

Could someone help me how do I fix this request to mongo?

I thank you and I'm waiting!

Hello Alisson ..

The mongodb2 node hasnt been updated for more that 4 years.
and other people have reported some problems with it also.

Can you try unistalling it and installing the more recent node-red-node-mongodb

ps. you can only have one version installed .. so make sure to uninstall the older one first


With newMsg.payload = { 'timestamp' : '/28\/08\/2021/' };
are you trying to use a regular expression pattern ?

try without the quotes

newMsg.payload = { 'timestamp' : /28\/08\/2021/ };

or

newMsg.payload = { 'timestamp': { $regex: '28\/08\/2021' } }

1 Like

Hello UnborN! Goodnight!

I removed the single quotes and it worked!!

Thanks for your help as it solved my problem!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.