MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. MongoDB is developed by MongoDB Inc. and is published under a combination of the GNU Affero General Public License and the Apache License.

Key features of MongoDB includes High Performance, Rich Query Language, High Availability, Horizontal Scalability, and Support for Multiple Storage Engines.

In this guide, we will explain how to install and configure MongoDB on a Debian 9 server.

To install MongoDB on CentOS 7, you can follow the guide here

To install MongoDB on Ubuntu 16/18, you can follow the guide here

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area and deploy your Cloudwafer cloud server.

Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:

sudo apt-get update && sudo apt-get upgrade

Step 1: Import MongoDB Community Edition Public Key:
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Run the following command to import the MongoDB public GPG Key:

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

Step 2: Create a list file for MongoDB
Run the command below to create the list file for MongoDB 4.2:

echo "deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

You can view the list using the command below:

cat /etc/apt/sources.list.d/mongodb-org-4.2.list

Step 3: Reload local package database*
Run the following command to reload the local package database:

sudo apt-get update

Step 4: Install the MongoDB packages
To install the latest stable version of MongoDB, run the command below:

sudo apt-get install -y mongodb-org

Step 5: Start MongoDB:
Issue the following command to start mongod:

sudo service mongod start

Step 6: Check the status of MongoDB:
Issue the following command to view the status of mongod:

sudo service mongod status

You can also certify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log

Step 7: Begin using MongoDB
Run the command below to start a mongo shell on the same host machine using the localhost address (in this case 127.0.0.1) and port that the mongod listens on by running the command below

mongo --host 127.0.0.1:27017