Save Preloader image


Latest News

Building the brands stronger and take you to
the next level of business!

Install & Secure MongoDB on Google Cloud Platform

By Jimish Parekh

Hey Database Explorers!

Here I am about to explain how to install MongoDB  and secure MongoDB on Google Cloud Platform. You can follow the same method on any virtual machine provider who allows you to start Ubuntu machines.

Let’s start installing MongoDB as we have successfully spin up our GCP Instance. Login to your instance and follow below commands to install mongodb.

Spin Up a machine on GCP

Login to your GCP Cloud Console here. After successful login, Go to your navigation panel and then :

Compute Engine > VM Instances

*You may have to enable billing here.

Once your VM Instances screen is there. Let’s spin up a machine for you.

Here are the configuration I have used, you can use as per your convenience :

  1. Appropriate VM Name
  2. Properly tag your VM
  3. Basic memory required is 2 GB, so you can go ahead and select your instance type.
  4. OS type – ubuntu, version – 18.04 LTS
  5. Allow HTTP & HTTPS Traffic (conditional)

Click on “Create

That’s it you are good to go.

Install MongoDB

First, update the packages list to have the most recent version of the repository listings:

sudo apt update

Let’s install mongodb package now:

sudo apt install -y mongodb

Checking status of MongoDB

I hope MongoDB installation went well, if not check for errors and just google it. Otherwise let’s check for the status of MongoDB.

sudo systemctl status mongodb

Status should be Active (Running). Check below image for reference.

Running Insecure MongoDB

To check if you can Run your mongo service, just type following command in your terminal:


Just check how many databases are there by default in mongo console.

show dbs

Securing MongoDB

Let’s create a first user in your mongodb “admin” database.

use admin

    user: “jimish”,
    pwd: “Pa$$Tutorial”,
    roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]

You should receive successfully created a user message. You can now logout from the mongo console. We will go ahead and secure your mongo service.

Traverse through your file management. open /etc/mongodb.conf in editable format. (via vim or vi or nano)

bind_ip =
port = 27017
auth = true

Please restart your mongodb service by following command

sudo systemctl restart mongodb

Try to login without providing information about credentials to mongodb


This should not let you login to mongo console as you have authenticated your database.

Executing Secure Mongo

Let’s login to your secure mongodb now.

mongo –port 10618 -u jimish -p –authenticationDatabase admin

This will ask for password prompt. Just enter your password and play around.

Happy Coding!!

(1) Comment

[…] to your particular database in MongoDB. If you have not secured your MongoDB please go to this blog and follow […]

Add Comment