Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Getting Started With MongoDB Setting Up MongoDB

Marius Unknown
Marius Unknown
12,925 Points

How to setup MongoDB on Windows CMD or GitBash with shortcuts.

Command Prompt (CMD)

Download MongoDB from original source. Install it. Turn on CMD terminal and write:

rundll32 sysdm.cpl,EditEnvironmentVariables

Then edit User Variables > Path and add new link "C:\Program Files\MongoDB\Server\3.4\bin\"

Now you can write to CMD console 'mongod' and 'mongo' to run the server.

How to make a permanent folder shortcuts for directories

Open CMD and write:

copy NUL shortcutName.bat

notepad shortcutName.bat

in the file write and save:

@echo on
cd C:\your\link
cls

Re-open CMD and call 'shortcutName'.

GitBash (not recommended because of crashes)

Download MongoDB from original source. Install it. Turn on GitBash terminal and write:

$ cd~
$notepad .bashrc

For sure I don't know why my .bashrc file is in cd~ directory (c/users/Marius). If you can't find it just create it. Then enter and save some alias (shortcuts):

alias mongod="/c/Program\ files/MongoDB/Server/3.4/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/3.4/bin/mongo.exe"

Now you can re-open your terminal and write 'mongod' to open mongo daemon and in another tab 'mongo' to open mongo shell. In the same way you can create other alias/shortcuts for your desired directories.

Good luck.

nico dev
nico dev
20,364 Points

You're the man! That was great.

Thanks for all your effort, Marius Zaleskis!!

2 Answers

Many thanks for this Marius!

Just as an amendment, for anyone reading this in Feb 2018 and using the GitBash method (the only one that worked for me), the current version of MongoDB is 3.6, so your .bashrc file should read as:

alias mongod="/c/Program\ files/MongoDB/Server/3.6/bin/mongod.exe"

alias mongo="/c/Program\ Files/MongoDB/Server/3.6/bin/mongo.exe"

Gabbie Metheny
Gabbie Metheny
33,778 Points

This is great!

I had a hard time figuring out how to get git bash to include the --dbpath flag, so for anyone who isn't using the default data/db location, this should work! I had to enclose the full mongod.exe path in quotes (with additional escaped quotes due to the space in the path), then escape a space, then the --dbpath flag in a separate set of quotes (and like Richard said, make sure you put your version of mongo in the path, and obviously change the dbpath to your own path!).

alias mongod="\"C:/Program Files/MongoDB/Server/4.0/bin/mongod.exe\""\ "--dbpath=C:/Users/Gabbie/data/db";
alias mongo="\"C:/Program Files/MongoDB/Server/4.0/bin/mongo.exe\"";