I can't connect to MongoDB. In Ubuntu it works, but I'm working in CentOS now. This is the error message:
MongoDB shell version: 2.4.2
connecting to: test
Sat Apr 20 07:22:09.390 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
I tried removing the mongod.lock
file, but it doesn't work.
Normally this caused because you didn't start mongod process before you try starting mongo shell. This case worked out for me, i had to do ~>sudo mongod --dbpath /dbpathlocation and then opened the new terminal to run mongo...
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.
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.
To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.
If you are running Ubuntu, then there is an issue with folder ownership.
Run these commands:
Stop the MongoDB service
sudo service mongodb stop
Remove the MongoDB lock file
sudo rm /var/lib/mongodb/mongod.lock
Change ownership from root to the MongoDB path
sudo chown -R mongodb:mongodb /var/lib/mongodb/
Start the MongoDB service
sudo service mongodb start
Test the mongo application
mongo
Then you will be able to execute successfully (I hope).
Reference: an answer on Stack Exchange site Database Administrators to Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 when changing mongodb data directory!
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