0

I started learning mongoDB a couple of days ago. Post installation, I am trying to change the dbpath as follows:

mongod --dbpath C:\myfolder\myproj\data\db

running the above command, I got the below statements in the command line:

Now i typed the below command to check if the dbpath has changed

mongod dbpath

this line still returns:

C:\data\db

I also tried running the below command to change the dbpath (as mentioned in a youtube video https://www.youtube.com/watch?v=pWbMrx5rVBE, but still the dbpath didn't change

mongod --directoryperdb --dbpath c:\myfolder\myproj\data\db

Can someone tell me how can I change my dbpath?

I looked at the stackoverflow question MongoDB not using /etc/mongodb.conf after I changed dbpath and also Unable to change the dbpath in mongodb through mongodb.conf but none of them helped

Community
  • 1
  • 1
Rahul Singh
  • 374
  • 4
  • 13

1 Answers1

3

When you run

mongod --dbpath C:\myfolder\myproj\data\db

You are starting an instance of mongod with it's data directory as C:\myfolder\myproj\data\db

Running a second

mongod dbpath

is effectively starting a new instance of mongod - which, by default, has its dbpath as \data\db

Just run mongod --dbpath C:\myfolder\myproj\data\db as you are, then use mongo to connect to it (or whatever client you're using)
When connecting to that instance, you'll be using the instance that is storing it's data in C:\myfolder\myproj\data\db

Alex
  • 37,502
  • 51
  • 204
  • 332
  • Hi Alex, Is there a way to then find the dbpath of that particular instance? – Rahul Singh Jan 07 '17 at 11:13
  • @RahulSingh see this - http://stackoverflow.com/a/39651696/131809 in short, check your task manager and see path to executable – Alex Jan 07 '17 at 11:16