14

I've installed mongodb then I've created a mongo service:

 [Unit]
    Description=High-performance, schema-free document-oriented database
    After=network.target

    [Service]
    User=mongodb
    ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

    [Install]
    WantedBy=multi-user.target

But When I launch the service and then I check the status, I get always this error:

● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-04-24 13:08:55 UTC; 6min ago
  Process: 1094 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=48)
 Main PID: 1094 (code=exited, status=48)

Apr 24 13:08:54 ip-172-31-37-163 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Unit entered failed state.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Failed with result 'exit-code'.

5 Answers 5

18

The problem was in config file and changing

bindIp: 127.0.0.1, X.X.X.X

to

bindIp: [127.0.0.1, X.X.X.X]

Solved my issue

1
4

Try changing the owner permissions

chown -R mongodb:mongodb /var/lib/mongodb

chown mongodb:mongodb /tmp/mongodb-27017.sock

2

In MongoDB 3.6 the brackets proposed by @Chlebta did not work for me, returning the error:

mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

My mistake was separating the IP addresses with commas and spaces. There has to be only commas between the addresses:

bindIp: 127.0.0.1,X.X.X.X,Y.Y.Y.Y
10
  • There is no capital 'P' to bindIp. Even with that correction I'm still stuck. Feb 3, 2018 at 12:25
  • True. Misspelling fixed, thanks. Also, look for tabs in the file. The conf file only works with spaces. Feb 3, 2018 at 17:19
  • I'll check that. I think the issue is that those IP need to be on the same network and I'm trying to allow an external IP access to the database. Feb 3, 2018 at 18:37
  • Ok. It should be possible. Use the IP address of the machine where you are editing the conf file, not the addresses of the external machines. I have 3 servers in Digital Ocean that communicate between them through VPN, so I used the private IP. Feb 3, 2018 at 19:26
  • Hmm that's what I'm doing already. But writing the IP of the machine I'm editing the conf file on is pretty much the same as writing 127.0.0.1, right? Here is my full problem. I have a machine with an Express/Nodejs server and a MongoDB/Mongod daemon installed on it. If I write BindIp : www.myAddress.com in the conf file the server talks to the data base just fine. What I want to be able to do is browse my database with Mongo Compass from another computer without the bindAllIp : true parameter. Feb 4, 2018 at 11:03
1

Update for Ubuntu 20.04 and MongoDB server version 4.4.2...

The issue for me ended up being that I was trying to use my machine's public IP address.

Once I specified my private IP address, everything started working. The mongod service starts without any errors, and I am now able to connect to it from remote machines.

On Ubuntu, you can use the following command to get your private IP address:

hostname -I | awk '{print $1}'

Here's what I have in /etc/mongod.conf (only showing relevant sections, and partial private IP address):

net:
  port: 27017
  bindIp: 127.0.0.1, 172.##.##.##

security:
  authorization: enabled

Note that putting brackets around the two IP addresses (as in the accepted answer) did NOT work for me, and resulted in a mongod status code of 2 (effectively a syntax error in the mongod.conf file). Also the space after the comma seems to work now, though not required.

1
  • 1
    This fixed it for me on 18.04 as well
    – Madbreaks
    Aug 9, 2021 at 21:49
-4

I just reboot system (sudo reboot) it is working for me. i don't know why.

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