How to set default dbpath for mongoDB in windows 7?

Another way to solve this is to simply make a batch file that runs the mongod command with the specified parameters. To do this, open a text file, make its contents:
mongod --dbpath "C:\Program Files\MongoDB\data\db"

Next save the file with a .bat extension then place it in the directory that mongod.exe is in. Whenever you would run mongod, instead run the batch file and you have effectively changed the default dbpath in windows.


You are almost close. In Windows, MongoDB can be installed as Service, the installation chapter of official document gives detailed instruction on how to get that done.

You mentioned "But as there were no default mongod.cfg file, now I have to run the command with --config". If you successfully install the MongoDB as service, you don't have to start and stop like that. The command will be as following:

 net start MongoDB

 net stop MongoDB

Actually, if you don't mind starting MongoDB when windows starts, you can also set MongoDB as auto-start service in Windows Service part.