MongoDB on Linux distribution ( Ubuntu 20.04 LTS )

In this article guide, I will show you how to install, run, and uninstall MongoDB on ubuntu 20.04.

MongoDB is one of the most popular NoSQL databases. MongoDB is used to store and work on data without the use of schema or ordering patterns. The MongoDB NoSQL database is widely used in web applications because it has easier integration with various programming languages.


Install MongoDB NoSQL Database:

MongoDB is very easy to install, and it is present in Ubuntu 20.04 software repository.

Step 1:

As always, first, update and upgrade your APT.

Terminal :

$ sudo apt update


$ sudo apt upgrade


Step 2:

Now download and install it via the following terminal command. It requires root privileges so type sudo with command.


Terminal :

$ sudo apt install mongodb



Step 3:

MongoDB is installed on your system now and it starts automatically after installation. To check the status of this database, type the following command in the terminal window.


Terminal :

$ sudo systemctl status mongodb



Run MongoDB service:

MongoDB service needs the systemctl command to modify its state. It requires root privileges so sudo must be used before every command.


MongoDB status checking:

The following command is used to check the status.


Terminal :
 

$ sudo systemctl status mongodb



MongoDB starts command:

MongoDB can be started through the following command.


Terminal :

$ sudo systemctl start mongodb



MongoDB stop command:

MongoDB can be stopped with this command.


Terminal :

$ sudo systemctl stop mongodb



MongoDB restart command:

In case you run into some errors and restart is compulsory then type the following command.


Terminal :

$ sudo systemctl restart mongodb



Enable option MongoDB when the system boots:

 
Terminal :

$ sudo systemctl enable mongodb



Disable option for MongoDB when the system boots:


Terminal :

$ sudo systemctl disable mongodb

By default, MongoDB is enabled after installation.

 

Starting MongoDB shell:

To work on the databases, you can open the “mongo shell” with the following terminal command.


Terminal :

$ sudo mongo


Uninstall MongoDB:

In case you do not need MongoDB and want to uninstall it then enter these three commands.


Terminal :

$ sudo systemctl stop mongodb


This command will stop the service.

Terminal :

$ sudo apt purge mongodb 

$ sudo apt autoremove



These two commands will uninstall the MongoDB database. This will wipe out all the database files so make sure that you have backed up your necessary files.



Comments

Popular Posts