These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.
If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.
To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.
Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
sudo mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
Step 4: Check status of mongodb.
sudo status mongodb
or
sudo service mongodb status
Step 5: Start mongo console.
mongo
Did you run mongod
before running mongo
?
I followed installation instructions for mongodb from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/ and I had the same error as you only when I ran mongo
before actually running the mongo process with mongod
. I thought installing mongodb would also launch it but you need to launch it manually with mongod
before you do anything else that needs mongodb.
This it's because the mongod process it's down, you must to run the commands bellow in order to get up the mongod process:
~$ sudo service mongodb stop
~$ sudo rm /var/lib/mongodb/mongod.lock
~$ sudo mongod --repair --dbpath /var/lib/mongodb
~$ sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
~$ sudo service mongodb start
Hope this helps you.
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.
Try
sudo service mongodb start
This solved my issue.
MAC OS
if you have mac and useing mongodb4.4, you can run:
brew services start [email protected]
Check your filesystem free space and increase it if its less. This also could cause the mongo not to start. Check the /var/log/mongodb/mongodb.log file.
ERROR: Insufficient free space for journal files
Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With