I just installed mongoDB in my windows machine
MongoDB version : Windows 64-bit 2008 R2+ release 3.0.4
OS Version : Microsoft Windows 7 Ultimate 64-bit
Installation Directory: "C:\Program Files\MongoDB"
instead of creating the database in default C:\data\db\
, I created a directory in the installation directory, i.e. C:\Program Files\MongoDB\data\db
. Now I can run mongod
server by the command
mongod --dbpath "C:\Program Files\MongoDB\data\db"
If I run only mongod
it throws an exception saying
[initandlisten] exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating
So, apparently the default dbpath is set to C:\data\db\
. Each time I run mongod, I have to explicitly specify --dbpath
Is there a way to override the default dbpath
value? I have tried following this answer, which solved the issue. But as there were no default mongod.cfg
file, now I have to tun the command:
mongod --config "C:\Program Files\MongoDB\mongod.cfg"
Which doesn't help much, because now I have to explicitly specify --config
each time. All I want to do is just type mongod
, each time I want to start mongo server. How can this be done?
By default, MongoDB listens for connections from clients on port 27017 , and stores data in the /data/db directory. On Windows, this path is on the drive from which you start MongoDB.
Go to C:\Program Files\MongoDB\Server(Version)\bin. Copy this file location.
Click on environment variables button under the advanced tab in system properties dialog. Select path variable and click on the edit button. Add new path variable, copy and paste the bin path location of the MongoD files installed. In my system, MongoDB is installed in “C:\Program Files\MongoDB\”.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With