Question:
I have followed AWS’ instructions (link) for installing MongoDB on AWS, and things seem to work until I try to connect to it.
When I run mongo
, I get this connection error:
1 2 3 |
2015-07-21T23:07:01.188+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2015-07-21T23:07:01.188+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146 |
And that happens even if I comment out the bind_ip
setting in the mongod.conf file (a common suggestion on forums), or set it to 0.0.0.0. Mongo did install, as I can run mongo --nodb
successfully. Can someone suggest help with my connection problem?
Thanks in advance!
EDIT: Whoops, my script had not the permissions needed to start the mongo daemon, so I started it manually with sudo service mongod start
, and now it works! Thanks!
Answer:
“mongo –nodb” will start a “dummy mongod service” and connect you directly into to it.
“mongo” will try to find a mongod service on port 27017 (standard port) on 127.0.0.1 (standard host). Equals: mongo –host 127.0.0.1 –port 27017
To check if your mongod service has started on your server:
1 2 3 |
$ ps -aux | grep mongo #check if service runs $ netstat -nap | grep 27017 #check if port is 27017 |
Start your mongod service:
1 2 |
$ sudo service mongod start |
If still not working, check your logfile:
1 2 |
$ tail -n100 /var/log/mongodb/mongodb.log |