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
Prompting for User Input in Assembly Ci20 Seg Fault
Delete .Ds_Store Files in Current Folder and All Subfolders from Command Line on MAC
How to Create a Directory and Give Permission in Single Command
Check Whether a Certain File Type/Extension Exists in Directory
Indenting Multi-Line Output in a Shell Script
Building Linux Kernel on MAC Os X
How Does Epoll's Epollexclusive Mode Interact with Level-Triggering
How to Write Non-Ascii Characters Using Echo
How to Programmatically Switch to a Specific Window in Compiz
How to Use Curl in a Shell Script
How to Install Cargo on a Rhel Linux Server
How to Get the Current Network Interface Throughput Statistics on Linux/Unix
Move Window Between Tmux Clients
I Get "Dquote>" as a Result of Executing a Program in Linux Shell
How to Add My Own Software to a Buildroot Linux Package
How to Download a File from the Internet to My Linux Server with Bash