Errr 'Mongo.Js:L112 Error: Couldn't Connect to Server 127.0.0.1:27017 at Src/Mongo/Shell/Mongo.Js:L112'

Errr 'mongo.js:L112 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112'

Try to remove /var/lib/mongodb/mongod.lock and restart mongdo service

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart

MongoDB - couldn't connect to server 127.0.0.1:27017, caused by :Connection refused : connect@src/mongo/shell/mongo.js:374:17

I ran the following in command line to fix the problem.

mongod --dbpath /usr/local/var/mongodb

this was directly after a re-install.

The error message that clued me in was:

{"t":{"$date":"2021-04-22T11:33:48.608-04:00"},"s":"E", "c":"STORAGE", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}

more specifically

"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27

Based on your mongod.conf file, MongoDB will run on port 27042. When you run the command mongo without parameter --port, it will connect to the default port 27017 then you have the error.

I think this command mongo --port 27042 will work.

Why can I connect to Mongo in node using 127.0.0.1, but not localhost?

As you pointed out, it seems that localhost resolves to IPv6 address ::1 and not 127.0.0.1.

You can keep using 127.0.0.1 or another option would be changing the address mongod service binds to, for instance, ::1 (you can bind to IPv4 and IPv6 at the same time).

mongo - couldn't connect to 127.0.0.1 - ip changed

If you want to connect to something other than the default host (which is "localhost"), you need to tell your Mongo client application about it.

For example, on the command line you can do

mongo --host 10.3.x.y db_name


Related Topics



Leave a reply



Submit