0

I'm using mac and I usually run mongodb using

mongod --dbpath=/Users/username/data/db

I also connect to my local db using MongoDB Compass. I install mongosh through brew cause I need to load a script using

load('scripts/script.js')

Inside the script, I connect using

db = connect("mongodb://localhost:27017/?readPreference=primary&ssl=false&directConnection=true"

);

Everything was running fine. Then I need to cleanup my collections so I drop my collections using the MongoDB compass.

I then run mongosh so I can load the script. This time, I got the following error

MongoNetworkError: connect ECONNREFUSED ::1:2701

I tried deleting /tmp/mongodb-27017.sock but still cannot connect. I closed my VSCode where I use to run commands in terminal and reopen and still cannot connect. I restarted my laptop and start mongod and run mongosh and load the script, still got the error mentioned. But I am still able to connect through Mongodb Compass.

iPhoneJavaDev
  • 821
  • 5
  • 33
  • 78
  • Ho do you connect? Maybe your problem is this one: https://stackoverflow.com/questions/74609210/cant-connect-to-mongodb-6-0-server-locally-using-nodejs-driver/74610881#74610881 – Wernfried Domscheit Feb 12 '23 at 16:19
  • i updated the question, added the way i connect in the script which was working before – iPhoneJavaDev Feb 12 '23 at 23:15
  • Does this answer your question? [Can't connect to MongoDB 6.0 Server locally using Nodejs driver](https://stackoverflow.com/questions/74609210/cant-connect-to-mongodb-6-0-server-locally-using-nodejs-driver) – Wernfried Domscheit Feb 13 '23 at 08:30

1 Answers1

0

Have you updated the version of Node.js recently? If so checkout this issue: https://jira.mongodb.org/browse/NODE-4538