Mongo: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
I assume that you followed the steps, outlined here.
Most probably you have a problem with mongo lock (or at least I had it once while installing on ubuntu). I solved it with the following commands:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
P.S. I by myself recently experienced this problem when I was updating my amazon ec2
instance. I have not properly shut down mongo before doing this and this resulted in a problem with mongo lock.
mongo - couldn't connect to server 127.0.0.1:27017
This error is what you would see if the mongo shell was not able to talk to the mongod server.
This could be because the address was wrong (host or IP) or that it was not running. One thing to note is the log trace provided does not cover the "Fri Nov 9 16:44:06" of your mongo timestamp
.
Can you:
- Provide the command line arguments (if any) used to start your
mongod process - Provide the log file activity from the mongod startup as well as
logs during the mongo shell startup attempt? - Confirm that your mongod process is being started on the same
machine as the mongo shell?
Couldn't connect to server 127.0.0.1:27017
The log indicates that mongodb is terminating because there is an old lock file.
If you are not and were not running with journaling, remove the lock file, run repair, and start mongodb again.
If you are or were running with journaling turned on, see the relevant Mongo DB docs. Note that they say "If you are running with Journaling you should not do a repair to recover to a consistent state." So if you were journaling, the repair may have made things worse.
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 even though I am running mongod
Create a directory /data/db and give permission to the MongoDB user so that MongoDB can access it. To create the directory:
sudo mkdir -p /data/db
To change owner:
sudo chown -R $USER /data/db
MongoDB Error couldn't connect to server
Execute the following command
sudo rm -rf /var/lib/mongodb/mongod.lock
then
sudo service mongodb restart
Error :couldn't connect to server 127.0.0.1:27017 MongoDB
I had the same problem. Looking into MongoDB log file, located in /var/log/mongodb/mongodb.log
, explained the reason - in my case it was:
ERROR: Insufficient free space for journal files
Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
Related Topics
List Files Over a Specific Size in Current Directory and All Subdirectories
Difference Between Unix Domain Stream and Datagram Sockets
Reading Data from PDF Files into R
Find All Zero-Byte Files in Directory and Subdirectories
How to Change File Permissions in Ubuntu
Best Distributed Filesystem for Commodity Linux Storage Farm
Shell Init Issue When Click Tab, What's Wrong with Getcwd
Sanitize Environment with Command or Bash Script
Linux: Which Process Is Causing "Device Busy" When Doing Umount
Shell Script to Count Files, Then Remove Oldest Files
How to Call Curl Without Using Server-Side Cache
How to Set the Grep After Context to Be "Until the Next Blank Line"
Linux: Set Permission Only to Directories
How to Make Vim Play Typewriter Sound When I Write a Letter
Adding a Header into Multiple .Txt Files
Bash Script Runs One Command Before Previous. I Want Them One After the Other