How to connect MongoDB with node-red

I have this flow


when I try to deploy my flows I get this message Error: More than 1 database name in URL
here is my url : mongodb+srv://username:password1234@cluster0.hx0l5.mongodb.net/capteurs?retryWrites=true&w=majority

Might be due to specifying the database name "capteurs" in the host field and in the database field?

Try setting the connection host to the host name / cluster DNS name only (i.e. remove /capteurs) as suggested in the readme

1 Like

I still have the same error

@sabayke

You currently have a full url in the Host field - including <username>:<password> and other details.

Have you tried with just the Host name in that field - cluster0.hx0l5.mongodb.net ?

yes but i get this error MongoError: failed to connect to server [cluster0.hx0l5.mongodb.net:27017]

Ah right - you're trying to use the srv record... I assume the node doesn't know how to work with those.

If I remember rightly, the hosted mongodb service can also provide you the 'normal' hostname/IP to use, rather than the +srv connection string.

Another possible reason .. although i havent worked with cloud based mongo dbs .. could be that Atlas server requires a step to whitelist an IP from where you want to access the cluster.

Add Your Connection IP Address to IP Access List

@sabayke Have you done this step ?

that's right !

With the Compass tool.. can you connect to your cloud db ?

Also .. what mongodb node / version are you using ?
That configuration screenshot doesnt look like its the node-red-node-mongodb 0.2.4

Can you try the above node instead that is more often updated and its config has options closer to your needs

image

yes when i try to connect compass with my db it work nicely

ok i will do it

i have 2 versions image

i guess you have to uninstall the other node first

i tried this image

but i didn't change anything

you have to be in the c:\Users\owner\.node-red folder to run that command
and make sure node red is not running

but why dont you uninstall it from the Palette that is easier ?
first you have to delete any instances of the mongo nodes in your flows and also any Configuration nodes related to it

i get this

You are using again the whole string .. use only the server cluster0.hx0l5.mongodb.net in HOST

1 Like

it work thank you so much

1 Like

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