How to setup MongoDB on Windows - Robin Wieruch

How to setup MongoDB on Windows - Robin Wieruch

This is a tutorial for setting up MongoDB on Windows. You might be wondering why there’s a need for another setup guide for MongoDB in the first place, since there are a few across the web. I found many tutorials and guides on how to set it up, but found most of them to be unclear and outdated, based on old MongoDB versions. The checklist is not comprehensive, though, as it is used for several tutorials on my website, I keep it updated with the recent versions of MongoDB. If you spot any flaws in this guide, a comment below would be very helpful to keep it up to date for other developers.

If you want to run MongoDB on MacOS instead, you will find guidance over here: How to setup MongoDB on MacOS . Make sure to read it as well, even though you are on Windows, because this guide only shows you the Windows installation for MongoDB but not how to create databases or how to interact with them. That’s covered in the MacOS guide instead.

For Microsoft Windows, it requires a manual download of the installer (.msi) from the MongoDB Download Center :

To use MongoDB on Windows, the bin folder must be included under thepath in the environmental variables. To do this navigate to System Properties and find the Advanced System Settings tab, where the Environmental Variables button can be seen at the bottom of the Window below Startup and Recovery. Add the directory C:\Program Files\MongoDB\Server\4.0\binunder the system variablePath. Here, 4.0 is for the versions 4.x.x , in the future it can be different depending on your version. You can verify the installation in the command prompt by navigating to the MongoDB installation folder and running this command:

You need to create a directory so MongoDB can store its data.

Now you will run mongo daemon. Which is a service which runs in the background and listens for connections on a given port. Run this command:

Now mongo daemon will be running in the background and can be used by your applications. I recommed using the latest version of libraries and software whenever possible to avoid compatibility issues with client-side applications.

Recommended articles