When ever I try to connect to mongo db I always get this error as below.
MongoDB shell version: 2.4.3 connecting to: test Fri Apr 26 14:31:46.941 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 various solutions listed in stackoverflow and tried following commands but nothing works.
1) sudo rm /var/lib/mongodb/mongod.lock
// says such file located at this place.
2) sudo service mongodb start
// error: sudo: service: command not found
3) I've made sure nothing else is running at that port.
4) Even tried uninstalling and installing it again.
5) Also tried kill pid
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 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.
MongoDB can be managed remotely or connected to a separate application server by making a few changes to the default configuration. First, we'll install the MongoDB using the docker container, then configure the MongoDB installation to access from a trusted remote machine securely.
Same error here, this worked for me:
sudo mongod --repair
followed by
sudo mongod
(forget about service and start)
Then on a different tab/terminal:
mongo
Start mongod server first
mongod
Open another terminal window
Start mongo shell
mongo
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