Home > Net >  How to specificy path of new collection in Mongo DB?
How to specificy path of new collection in Mongo DB?

Time:03-14

I am running Mongo on Windows 10. Data access is made trugh Pymongo (Python). All my data is stored in an old large HDD, but I would like to have some smaller collection stored on a much faster SSD? When I create a new collection either trough Compass or Pymongo there is no option to specify the path on disk.

Is it possible to learn such power?

CodePudding user response:

If you want to have databases in different disks under the same dbPath , this is the option:

  1. Add the option --directoryperdb in the mongod config file or at startup.

  2. db.createDatabase("newDatabase")

  3. You will see inside the dbPath folder for the new database like: \dbPath\newDatabase

  4. Stop the mongodb process.

  5. Copy the content from \dbPath\neWDatabase to your SSD let say: ssd:\newData

  6. make link to the folder with:

    mklink /d \newData \dbPath\newDatabase
    

or follow this tutotial

  1. Start the mongodb process again.

Note: As suggested by @Wermfried in the comment it is safe to have the option --directoryperdb set initially in the member before to get populated ...

CodePudding user response:

If you're on windows, create the configuration file mongod.cfg. And add the entry as

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db
net:
    bindIp: 0.0.0.0
    port: 27017

Learn more at - https://www.ge.com/digital/documentation/meridium/Help/V43020/Default/Subsystems/ModuleDeployment/Content/ConfigureAWindowsServiceForMongoDB.htm

  • Related