Skip to content

Instantly share code, notes, and snippets.

@nickvoronin
Last active October 12, 2018 11:13
Show Gist options
  • Save nickvoronin/cb0ccd763d0976a110e23e24afa0d02c to your computer and use it in GitHub Desktop.
Save nickvoronin/cb0ccd763d0976a110e23e24afa0d02c to your computer and use it in GitHub Desktop.
# Locate
which mongo
locate -b '\mongo'
# Start
sudo service mongod start
# Check status
systemctl status mongodb.service
# On start error
# Failed to start mongod.service: Unit mongod.service not found.
sudo systemctl unmask mongodb
# Add to autorun
systemctl enable mongod.service
# change dbPath
/etc/mongod.conf
mongod --config /etc/mongod.conf
If you run ps -xa | grep mongod and you don't see a --dbpath which explicitly tells mongod to look at that
parameter for the db location and you don't have a dbpath in your mongodb.conf, then the default location
will be: /data/db/ and you should look there.
# Remove
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
# OR
Normally, with apt command, you can launch autoremove with all mongoDB packages :
sudo apt-get autoremove mongodb-*
https://askubuntu.com/questions/990727/error-removing-broken-mongo-server-package
###
https://stackoverflow.com/questions/37014186/running-mongodb-on-ubuntu-16-04-lts
# use sudo for all the following steps
create a service script (in this example the name of the service is Mongodb)
nano /lib/systemd/system/mongodb.service
File content should be
[Unit]
Description=MongoDB Database Service
Wants=network.target
After=network.target
[Service]
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=mongodb
Group=mongodb
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment