MongooseServerSelectionError: connect ECONNREFUSED

Hello, I am having trouble getting connected to my localhost MongoDB on Mac OS. I have read through countless forums and tried everything to get mongod and the mongodb-community server started, but nothing has worked. The error I am getting is below:

  const serverSelectionError = new ServerSelectionError();

MongooseServerSelectionError: connect ECONNREFUSED`

Can anyone help me with this please?


Is your mongod up and running on port 27017?
Can you connect by another tool like shell or Compass?

i have the same problem only when connecting in my nodejs app, but when connecting using shell or Compass there is no problem,


I just found a solution in the internet ,
If you are using latest nodejs (v17.x) , then try updating mongodb url from localhost to

This worked for me :slightly_smiling_face:


That worked for me too bro, thank you. <3


Big Thanks :white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower::white_flower:

Thanks bro :+1:, it worked for me also :100:

@Danaboina_Shanmukeshwar YOU’RE THE MAN!!! Thanks a lot. Worked for me very well. :raising_hand_man:t2: