6
> 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

Saket Suraj
  • 165
  • 1
  • 2
  • 10
  • 1
    https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition-on-ubuntu – Joe Aug 29 '20 at 06:23
  • please follow the instructions at the link mentioned by @joe and it should install/upgrade the mongodb version to 4.4 – vshenoy Aug 29 '20 at 10:32

3 Answers3

5

Just run the following commands in ubuntu 20.04:

sudo systemctl start mongod

Then run:

mongod --fork --logpath /var/log/mongodb/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb

Then run:

mongo

And it worked for me.

Saket Suraj
  • 165
  • 1
  • 2
  • 10
  • 1
    This did not work for me. I received the error `Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :` – Rylan Schaeffer Jan 18 '22 at 23:52
1

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

Because I was checking status without staring the mogodb start script

Jin Lee
  • 3,194
  • 12
  • 46
  • 86
Deepa Rokhade
  • 411
  • 4
  • 4
0

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
Aindriú
  • 3,560
  • 9
  • 36
  • 54