Cannot connect to MongoDb through N8N

Describe the issue/error/question

When I try to create a credential to a MongoDb database, I keep getting refused connection. I know the credentials are correct because I use the same connection string in MongoDb Compass and on R:

mongodb://user:[email protected]:27017/?readPreference=secondary

A bit frustating because I do not how to troubleshoot from here, except that I confirmed the connection string works in other enviroments, and turned off all firewalls, just in case. Any ideas on this would be appreciated!

What is the error message (if any)?

connect ECONNREFUSED ::1:27017

Please share the workflow

Not applicable

Share the output returned by the last node

Not applicable

Information on your n8n setup

  • OS: Windows 10
  • n8n version: 0.213
  • MongoDb version: 6.0.4
  • Database you’re using SQLite
  • Running n8n with the execution process own
  • Running n8n via npm:

Hey @KenupCF,

The machine is saying that the connection is being refused to port 27017 on localhost. Is MongoDB running on the same machines as n8n and neither of them in a docker container?

Hi @Jon,

Sorry for the delay on the reply. Yes, both of them are on the same machine, and none of them on a docker container.

I am happy to report I found a solution. It seems to be a NodeJS issue, and using “” instead of “localhost” on the connection string solved the issue.


Thank you very much for sharing your solution. Is very appreciated!

1 Like

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