0

The error I am receiving:

{ [MongoNetworkError: failed to connect to server [127.0.0.1:37017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:37017]] name: 'MongoNetworkError', [Symbol(mongoErrorContextSymbol)]: {} }

*I had set the port while setting up my local database as 37017.

A mongo client in a separate terminal window is able to connect to the local server and execute commands. The problem occurs when I try to connect to the same server using a NodeJs application. I am attempting to run this simple code:

Code Image

What I have tried:

1.Reinstalling mongodb and restarting server

2.Using localhost instead of 127.0.0.1

Edit: ps confirms a mongod daemon is running

I am fairly new to nodeJs and MongoDB so debugging this error this early on has become a major headache! I am on a Mac running OS Catalina if that is related. Thank you!

nishantmi
  • 1
  • 1
  • this could help: https://stackoverflow.com/questions/50173080/mongonetworkerror-failed-to-connect-to-server-localhost27017-on-first-connec, be sure you have the mongodb service running – Sidonai May 25 '20 at 19:29
  • Can you use `ps` to confirm that a `mongod` daemon is running? – Joe Drumgoole May 25 '20 at 20:02
  • Yes. I forgot to mention that in my question but ps confirms a mongod daemon is running. A mongo client is able to connect to it. – nishantmi May 26 '20 at 05:42

0 Answers0