How to install MongoDB on Linux Debian 9?

How to install MongoDB on Linux Debian 9?

The MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need. It stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time. The document model maps to the objects in your application code, making data easy to work with. Ad hoc queries, indexing, and real time aggregation provide powerful ways to access and analyze your data. MongoDB is a distributed database at its core, so high availability, horizontal scaling, and geographic distribution are built in and easy to use by

In this blog, we will install the MongoDB on Linux Debian 9. The step by step procedure has been given below to install MongoDB.

First, update all the existing packages by using below command.

sudo apt update

Then, install the MongoDB package by using apt install command.

sudo apt install -y mongodb

The above command installs the latest stable version of MongoDB and also it starts the MongoDB service automatically after the installation complete.

Now, this the time to verify the MongoDB service has been started or not on the Linux Debian 9.

Execute the below system control status command to see the status of MongoDB service.

 sudo systemctl status mongodb 

You will see the below output on the console.

Then, verify the MongoDB server connection by using diagnostic command.

mongo --eval 'db.runCommand({ connectionStatus: 1 })'

After executed the command, you will see the below output on the console with Database server version and OK attribute.

MongoDB shell version: 3.2.11
connecting to: test
        "authInfo" : {
                "authenticatedUsers" : [ ],
                "authenticatedUserRoles" : [ ]
        "ok" : 1

The OK field value “1” represents, database server is running without any issues.

Below commands are used to manage the MongoDB service by using system control commands.

To view the status of the MongoDB service.

sudo systemctl status mongodb

To stop the MongoDB service.

sudo systemctl stop mongodb

To start the MongoDB service when it stopped.

sudo systemctl start mongodb

To restart the MongoDB service.

 sudo systemctl restart mongodb 

By default MongoDB service will start when the system starts. To disable that execute the below command.

sudo systemctl disable mongodb

Execute the below command to enable the MongoDB service when the system starts.

sudo systemctl enable mongodb

The MongoDB successfully installed on the Linux Debian 9.