MongoDB is one of most widely used NoSQL database. MongoDB is open source.

If you are just starting with MongoDB, check out mongoDB cheat sheet for important commands.

Installing MongoDB

  1. Apt update packages
sudo apt update
sudo apt install -y gnupg
  1. Add MongoDB 4.4 repository
sudo apt-key adv --keyserver hkp:// --recv E52529D4
echo "deb [ arch=amd64,arm64 ] bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt update
  1. Install MongoDB 4.4
sudo apt install -y mongodb-org

4. Verify MongoDB Installation

Run following command...

sudo systemctl status  mongodb

Expected Output...

● mongodb.service - LSB: An object/document-oriented database
   Loaded: loaded (/etc/init.d/mongodb; generated)
   Active: active (running) since Sun 2020-08-23 21:51:18 UTC; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 26174 ExecStart=/etc/init.d/mongodb start (code=exited, status=0/SUCCESS)
 Main PID: 17543 (code=exited, status=0/SUCCESS)
    Tasks: 33 (limit: 2362)
   CGroup: /system.slice/mongodb.service
           └─26191 /usr/bin/mongod --config /etc/mongodb.conf

5. Check MongoDB Version

mongod --version

Expected output...

db version v4.4.0
Build Info: {
    "version": "4.4.0",
    "gitVersion": "563487e100c4215e2dce98d0af2a6a5a2d67c5cf",
    "openSSLVersion": "OpenSSL 1.1.1  11 Sep 2018",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "x86_64",
        "target_arch": "x86_64"

Common Errors While Installing MongoDB

  1. mongodb-org-server : Depends: libcurl3 (>= 7.16.2) but it is not going to be installed

Install libcurl4

sudo apt install librcurl4
  1. Failed to start mongodb.service: Unit mongodb.service is masked.

Run following command to fix above error...

sudo systemctl unmask mongodb
  1. Failed to start LSB: An object/document-oriented database.
    -- Subject: Unit mongodb.service has failed

Fix the ownership on /var/lib/mongodb

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