How To Install MongoDB Community Edition on Ubuntu 20.04

MongoDB is a NoSQL database, which is cross-platform, document oriented database. MongoDB able to offer high performance, high availability and scalability. The MongoDB advantages over RDMS
– No complex join
– Easy to scale
– Schema less
– High speed
– NoSQL injection

Install Dependency

We’ll need this dependency later on instalation process. It’s better to install all once, to avoid confusion for beginner.

sudo apt-get install curl wget gnupg2 ca-certificates -y

install dependency mongodb

Install MongoDB PGP Key

We must install the PGP key, to validate the mongodb file when installed using apt

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

Add MongoDB repository

This repository is an official repository from MongoDB

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

Update repository metadata

Everytime file repository updated, we must update the metadata using apt-get update

sudo apt-get update

Install MongoDB

sudo apt-get install mongodb-org -y

mongodb 4.4 install

Start MongoDB

sudo systemctl start mongod

Check MongoDB Status

sudo systemctl status mongod

mongodb status

Using MongoDB

After installing MongoDB, we must know the basic operation of MongoDB. The simple query that we’ll use create, insert, update and delete (CRUD).

Login to mongodb

mongo

mongodb create

create database, example database

use users

Insert data to collection, collection is equivalent to table in RDBMS.

db.users.insert({"user":"atetux", "domain":"atetux.com"})

Show data from collection

db.users.find()

Update data

db.users.update({"user":"atetux"}, {$set:{"user":"atetux_updated"}})

Remove data

db.users.remove({"user":"atetux_updated"})

Leave a Comment