Random Number Generator (RNG)
Other Documentation
Installing MongoDB
MongoDB is a NoSQL database that has fully flexible index support and a rich queries database.
This document explains how to install MongoDB (as root/sudo).

Step 1 – Setup Apt Repository

First of all, import GPK key for the MongoDB apt repository on your system using the following command. This is required to test packages before installation
1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
Copied!
Then add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.
Ubuntu 18.04 LTS:
1
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
Copied!

Step 2 – Install MongoDB on Ubuntu

After adding required APT repositories, use the following commands to install MongoDB on your systems. It will also install all dependent packages required for MongoDB.
1
sudo apt update
2
sudo apt install -y mongodb
Copied!
If you want to install a specific version of MongoDB, define the version number as follows:
1
sudo apt install mongodb-org=4.2.1 mongodb-org-server=4.2.1 mongodb-org-shell=4.2.1 mongodb-org-mongos=4.2.1 mongodb-org-tools=4.2.1
Copied!

Step 3 – Manage MongoDB Service

After installation, MongoDB will start automatically. To start or stop MongoDB use an init script. For example:
1
sudo systemctl enable mongod
2
sudo systemctl start mongod
Copied!
And use the following commands to stop or restart the MongoDB service.
1
sudo systemctl stop mongod
2
sudo systemctl restart mongod
Copied!

Step 4 – Verify MongoDB Installation

Finally, use the below command to check the installed MongoDB version on your system.
1
mongod --version
2
3
db version v4.2.1
4
git version: edf6d45851c0b9ee15548f0f847df141764a317e
5
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
6
allocator: tcmalloc
7
modules: none
8
build environment:
9
distmod: ubuntu1804
10
distarch: x86_64
11
target_arch: x86_64
Copied!
And check the status with:
1
sudo service mongod status
Copied!
Important: Some versions have the service name as mongod and some have mongodb. If you get an error with the above command, use sudo service mongodb status instead.

Step 5 - Test MongoDB

Also, connect MongoDB using the command line and execute some test commands for checking proper working.
1
mongo
2
3
> use mydb;
4
5
> db.test.save( { tecadmin: 100 } )
6
7
> db.test.find()
8
9
{ "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "tecadmin" : 100 }
Copied!