1

I have Mongo installed on Ubuntu 16.04 machine, on VMWare. I start it using "mongo" command, last week there was no problem. But recently, it gives this error:

MongoDB shell version: 3.2.15 connecting to: test 2017-08-09T09:31:33.634+0300 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2017-08-09T09:31:33.712+0300 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:229:14 @(connect):1:6

exception: connect failed

I know how to solve it, it is here: https://stackoverflow.com/questions/12831939/couldnt-connect-to-server-127-0-0-127017/34835813#34835813

But everytime I reboot Ubuntu machine, the problem repeats. Why, and how can I prevent this happen everytime? Thanks.

Edit: Problem solved. You can see the solution below, in my comments to JJussi's answer.

migrated from stackoverflow.com Aug 9 '17 at 7:57

This question came from our site for professional and enthusiast programmers.

  • 1
    So set the mongod service to start automatically on boot. Not really a programming question, hence it's actually answered on other sites. askubuntu.com/questions/61503/… – Neil Lunn Aug 9 '17 at 6:47
  • I was automatically starting mongodb, using "sudo systemctl enable mongodb", now I also tried "sudo systemctl enable mongod.service" but it didn't work. Still I have the same problem. – jack jack Aug 9 '17 at 7:02
0

mongod is actual mongodb daemon what "is" the database. mongo is just client program what connects to mongod process (in this case; with sharded cluster it connects to mongos -process).

So, mongod process must be running before mongo can connect it.

You wrote that sudo systemctl enable mongod.service don't work anymore? Check if that service has (some how) changed its name. Just give command sudo systemctl|grep -i mongo and you can see if it is there and it is enabled. IF still your mongod process don't start automatically after reboot, check /var/log/mongodb/mongodb.log (you can check that lock file name with sudo grep path /etc/mongod.conf -command) says. What is the error? Fix that error (maybe chown of directory and files?) and try again with sudo systemctl restart mongod.service (or what ever is services name)

  • I think mongod has some problems. I'm trying to start it using sudo systemctl start mongod.service, when I check the status with sudo systemctl status mongod.service, this is the result: Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) Started High-performance, schema-free document-oriented database. mongod.service: Main process exited, code=exited, status=100/n/a mongod.service: Unit entered failed state. mongod.service: Failed with result 'exit-code'. – jack jack Aug 9 '17 at 9:14
  • now I repaired mongod using this: stackoverflow.com/a/12232668/8438046 Then I reboot computer and run mongo, no errors anymore, problem solved. Thanks. – jack jack Aug 9 '17 at 9:21
0

As MongoDB BOL Here The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and data file directories in /etc/mongod.conf.

If you change the user that runs the MongoDB process, you must modify the access control rights to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.

Issue the following command to start mongod:

sudo service mongod start

For your further ref Configuration File Options

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.