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.