Skip to content
Related Articles

Related Articles

Improve Article

How to Install and Configure MongoDB in Ubuntu?

  • Last Updated : 05 Mar, 2020

MongoDB is an open-source document oriented NoSQL database which is written in C++. MongoDB is schema-less database system and hence its very easy to add new fields in it. It is a distributed system hence data recovery is instant and more reliable.

Features of MongoDB

  • Document Oriented
  • No complex joins needed
  • Indexed Database
  • Scalability
  • Automatic Partitioning of Big Data

Installation of MongoDB

MongoDB can be installed on Ubuntu with the use of the following commands. These commands are easy to run on the terminal and make the installation process handy. Follow the steps given below to install MongoDB:

Step 1: First you need to update and upgrade your system repository in order to install MongoDB. Type the following command in your terminal and then press Enter.

$ sudo apt update && sudo apt upgrade

MongoDB-Ubuntu-Installation-01
 
Step 2: Now, install the MongoDB package using ‘apt’. Type the following command and press Enter.

$ sudo apt install -y mongodb

MongoDB-Ubuntu-Installation-02
 
Step 3: Check the service status for MongoDB with the help of following command:



$ sudo systemctl status mongodb

MongoDB-Ubuntu-Installation-03
systemctl verifies that MongoDB server is up and running.
 
Step 4: Now check if the installation process is done correctly and everything is working fine. Go through the following command:

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

MongoDB-Ubuntu-Installation-04
the value “1” in ok field indicates that the server is working properly with no errors.
 
Step 5: MongoDB services can be started and stopped with the use of following commands:
To stop running the MongoDB service, use command :

$ sudo systemctl stop mongodb

MongoDB service has been stopped and can be checked by using the status command:

$ sudo systemctl status mongodb

MongoDB-Ubuntu-Installation-05
As it can be seen that the service has stopped, to start the service we can use :

$ sudo systemctl start mongodb

MongoDB-Ubuntu-Installation-06

Read more about systemctl command on systemctl in Unix

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :