Setting up your own MongoDB server

Sukhbeer Dhillon
2 min readJan 23, 2020

I began working on setting up a MongoDB server on a VM with Ubuntu. Below is a link to the official documentation for installation of the same.

Once done installing, check the status of your server as specified by the guide. Now, in order to connect to this server on the VM from your local machine, you basically have to make some changes in the configuration file. Change the default port from 27017 to whatever you mapped for MongoDB, for example 10001. This mapping will have a forwarded port that is exposed to the world, for example 6007. Next change in the config file is to make the bindIp from localhost to 0.0.0.0 so that any IP address can connect to your database.

However, there is a security risk in that. So, finally, enable security through authentication for your database. Below is a guide that will tell you how to make the exact changes.

Once you’re done with the above changes and have made an authorized user to access the database, use the following to connect from your local terminal

mongo "mongodb://yourvm.domainname.com:xxxx" -u [username] -p [admin password]

xxxx is the forwarded port for MongoDB (6001 for example as mentioned above). You can use the same connection string for your Node Server.

--

--