Download it from the official download page.
When asked if you want a "Complete" or a "Custom" installation, select "Custom". Don't change any installation default option, but uncheck the box that says "Run as a service". That would mean MongoDB is always turned on, even while you're not using it.
When asked if you want to install MongoDB Compass, accept it.
Edit your .bash_profile
file in the ~
directory. You can open it on VSCode by running code ~/.bash_profile
in your terminal.
Add the following line:
alias mongodb="mongod --config /usr/local/etc/mongod.conf"
If the above does not work, try adding the command to the ~/.zshrc
file.
After installing MongoDB on Windows, check that you're able to access the MongoDB executables by running "mongod" on your terminal. If you're told that the command was not found, you'll need to add the path to the executables to your environment vairables PATH.
To add on to the path, select the search bar and look up "environment", and the options to "Edit Environment Variables" should pop up. Open it. At the bottom, you should see a "Environment Variables..." button, click it. You should now see a list of "User Variables" and "Environment Variables". In the list of environment variables, you should see a variable named "PATH" or "Path, select it. You're able to add one more path to the "PATH" environment variable by clicking new and pasting in the path to your MongoDB installation. That path should be something like C:\Program Files\MongoDB\Server\4.2\bin
(replace the version for the version of MongoDB that you have installed). If you're unsure that this is the correct path, you can open that path on the file explorer by running the following on the command line: explorer C:\Program Files\MongoDB\Server\4.2\bin
. Close your terminal and reopen it. If everything worked correctly, running mongod
should show a MongoDB error message, but not that the command was not found.
Edit your .bash_profile
file in the ~
directory. You can open it on VSCode by running code ~/.bash_profile
in your terminal.
Add the following line:
alias mongodb="C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe\" --dbpath=\"C:\data\db\""
Note: You should replace the version of MongoDB for the one that you have installed.
At the root of your machine (~
, or where the terminal is initiated) run the following in the terminal:
mkdir data
cd data
mkdir db
If you've followed the previous instructions, you should now be able to just run the command mongodb
on your machine and that should instantiate MongoDB without outputting anything to the console.
You can confirm that MongoDB is turned on by opening MongoDB Compass and pressing "Connect".