install and configure mongodb

How To Install and Configure MongoDB On Ubuntu

We can install and configure the MongoDB database server on ubuntu. MongoDB is an open-source cross-platform document-oriented database program also known as the NoSQL database. It uses the JSON like document schema. we can also install MongoDB in Linux as well. 

Check Out: How To Create Elastic File System(EFS) On Amazon Cloud

Update the current packages with sudo apt update.

Once it’s finished, install the MongoDB using the below command.

sudo apt install mongodb

you can check MongoDB version using mongo command.

[email protected]:~# mongo
MongoDB shell version v3.6.3
connecting to: mongodb://
MongoDB server version: 3.6.3

Let’s check the services and enable them at boot time using the following commands.

systemctl status mongodb
[email protected]:~# systemctl status mongodb
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-22 12:57:59 UTC; 6min ago
Docs: man:mongod(1)
Main PID: 3249 (mongod)
Tasks: 24 (limit: 2290)
CGroup: /system.slice/mongodb.service
└─3249 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Mar 22 12:57:59 ubuntu systemd[1]: Started An object/document-oriented database.

we can enable and disable MongoDB service using systemctl enable mongodb && systemctl disable mongodb

if you want to stop service using this command systemctl stop mongodb

Check Out: Enable and Disable Journaling On EXT4 File Systems In Linux

Check the firewall status and allow the MongoDB port in the rules. so

[email protected]:~# ufw status
Status: inactive

Enable the firewall using ufw enable

[email protected]:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

check the status so

[email protected]:~# ufw status
Status: active

MongoDB uses port number 27017 and we need to allow the port in the firewall rules. so

[email protected]:~# ufw allow from to any port 27017
Rule added

Check Out: How To Install Node.js And NPM On Ubuntu 19.04

check the status of the rule on the ubuntu firewall. so

[email protected]:~# ufw status 
Status: active

To                        Action                     From
--                       ------                      ----
27017                     ALLOW          

Bind Ip in the configuration file vim /etc/mongodb.conf


bind_ip =,
#port = 27017

Restart the service so

systemctl restart mongodb

we can check the port should be listening on 27017 using the command so

netstat -tnlp | grep mongod
[email protected]:~# netstat -tnlp | grep mongod
tcp     0     0*     LISTEN    3749/mongod

You’re done install mongodb linux


Please enter your comment!
Please enter your name here