Securing your mongodb database

When setting up a Mongo database on a production environment, its considered a good practice to secure it. I have learned this in a hard way after my mongodb instance got hacked. So i’d encourage you to secure yours (in case you still haven’t) before it gets compromised.

Before you secure your existing database, you need to first secure the admin database that gets shipped with everyMongo database.

Login to your mongo shell and run the following command

The above command would create a new admin user (make sure you change the password in your case) with a root access and assign the user to the “admin” database.

Once this is done, you need to secure your own database. Run the following command…

The above command will create a new user “my_user” (don’t forget to change the password) with a “read” and “write”¬†access and assign that user to the “mydatabase” database.

Now, you need to specify the new username and password everytime you connect to your database.

Hope that helps!

Did you install mysqlclient or MySQL-python?

Its been a few weeks that I started building a small project after learning Django. I created my project under a virtualenv and when I ran the following command to migrate the database


I encountered with a weird kind of error.

I was having a hard time figuring out what was causing the error, I did a lot of googling before i finally found the solution.

To resolve the error I ran the following commands

followed by

and hola, everything worked like a charm