'Mongodb: Active: failed (Result: exit-code)

> mongod.service - MongoDB Database Server
>      Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
>      Active: failed (Result: exit-code) since Tue 2020-09-08 02:53:14 IST; 7min ago
>        Docs: https://docs.mongodb.org/manual    Main PID: 6128 (code=exited, status=2)
> 
> Sep 08 02:53:14 saket-HP-ProBook-440-G4 systemd[1]: Started MongoDB
> Database Server. Sep 08 02:53:14 saket-HP-ProBook-440-G4 mongod[6128]:
> Error parsing YAML config file: yaml-cpp: error at line 24, column 3:
> end of map not fo> Sep 08 02:53:14 saket-HP-ProBook-440-G4
> mongod[6128]: try '/usr/bin/mongod --help' for more information Sep 08
> 02:53:14 saket-HP-ProBook-440-G4 systemd[1]: mongod.service: Main
> process exited, code=exited, status=2/INVALIDARGUMENT Sep 08 02:53:14
> saket-HP-ProBook-440-G4 systemd[1]: mongod.service: Failed with result
> 'exit-code'. Sep 08 02:58:34 saket-HP-ProBook-440-G4 systemd[1]:
> /lib/systemd/system/mongod.service:11: PIDFile= references a path
> below legacy directory > Sep 08 03:00:52 saket-HP-ProBook-440-G4
> systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references
> a path below legacy directory > lines 1-13/13 (END)

I have tried all the available solutions and unfortunately they are not working for me. I am using ubuntu 20.04



Solution 1:[1]

Make sure you have entered this command : sudo systemctl start mongodb

Because I was checking status without staring the mogodb start script

Solution 2:[2]

I had a problem installing MongoDB on Ubuntu 21.10, after following the steps outlined in the official documentation I got the same error as the O.P. The following steps worked for me (reboot required)

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10</span>

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo apt-get install -y mongodb-org=3.4 mongodb-org-server=3.4 mongodb-org-shell=3.4 mongodb-org-mongos=3.4 mongodb-org-tools=3.4

Then open the following with an editor (VIM in this case - use :wq to write and quit)

sudo vim /etc/systemd/system/mongodb.service

Paste :-

#Unit contains the dependencies to be satisfied before the service is started.
[Unit]
Description=MongoDB Database
After=network.target
Documentation=https://docs.mongodb.org/manual
# Service tells systemd, how the service should be started.
# Key `User` specifies that the server will run under the mongodb user and
# `ExecStart` defines the startup command for MongoDB server.
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
# Install tells systemd when the service should be automatically started.
# `multi-user.target` means the server will be automatically started during boot.
[Install]
WantedBy=multi-user.target

Then continue with a reload and a start..

systemctl daemon-reload

sudo systemctl start mongodb

You might just need a reboot after all that... Check status and enable with the following:

sudo systemctl status mongodb
sudo systemctl enable mongodb

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jin Lee
Solution 2 Aindriú