Install MongoDB on Ubuntu 18.04

How Install MongoDB on Ubuntu 18.04..

What is MongoDB ?

MongoDB is a free and open-source NoSQL document database which uses JSON-like documents with schemata. It means fields can vary from document to document and data structure can be changed over time.

In this tutorial we will learn how to install MongoDB, manage MongoDB service, and enable remote access.

First we will update package list so we will have more recent repository version listing.

Command to update package list on Ubuntu 18.04 is

apt update

Now install MongoDB using command

apt install mongodb -y

This command will install latest version of mongodb on your server along with management tools required for mongodb server.

Let’s check status of mongodb service installed using command

systemctl status mongodb

If you see active running then it is up and running.

We will execute further command to connect mongodb server

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

Above command will provide version of mongodb server as output.

Output should be like:

MongoDB shell version v3.6.3
connecting to: mongodb://
MongoDB server version: 3.6.3
        "authInfo" : {
                "authenticatedUsers" : [ ],
                "authenticatedUserRoles" : [ ]
        "ok" : 1

Here ok: 1 means service mongodb is ready to use.

Below are command to start, stop, restart.

systemctl start mongodb

systemctl stop mongodb

systemctl restart mongodb

By default it is enabled for onboot start. Command to disable/enable ie. to disable automatic start on server boot is

systemctl disable mongodb

To enable automatic start of mongodb server on server boot is

systemctl enable mongodb

Port used by mongodb server is 27017. You need to open this port in firewall if you want to allow access to this server from remote server.

Once you open port you will need to define IP of remote server in mongodb configuration.

vi /etc/mongodb.conf

find line starting with word bind_ip and then add all remote server IPs and separate them by comma for example to allow IPs and

Change line
bind_ip =
bind_ip =,,

Save file and restart mongodb service.

systemctl restart mongodb.


Leave a Reply

Your email address will not be published. Required fields are marked *