How to specificy path of new collection in Mongo DB?

524 Views Asked by At

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?

1

There are 1 best solutions below

3
On

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 ...