Install mongodb
sudo apt-get install mongodb
Acess mongodb.service and insert the configuration code
cd /lib/systemd/system
sudo vim mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
After=network.target
[Service]
Type=forking
User=mongodb
Group=mongodb
RuntimeDirectory=mongod
PIDFile=/var/run/mongod/mongod.pid
ExecStart=/usr/bin/mongod -f /etc/mongod.conf --pid filepath /var/run/mongod/mongod.pid --fork
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
Enable mongo.service
sudo systemctl enable mongodb.service
sudo mkdir -p /data/db
sudo chown -R mongodb /data/db
sudo vim /etc/mongodb.conf
Replace dbpath=/var/lib/mongodb by dbpath=/data/db
If you face a problem
sudo service mongodb start
sudo systemctl status mongodb.service
If mongod.lock exists at /data/db then
sudo rm /data/db/mongo.lock
mongod --repair
sudo service mongodb start
To run mongodb, make sure to
sudo service mongodb stop
then you can run mongodb like that
sudo mongod
and in an other terminal run
mongo