How to create multiple databases in different locations on a computer?

Is it feasible to create multiple MongoDB database at different locations on a computer while operating on the same port?

Check

1 Like

I am encountering a problem when trying to set directoryPerDB to true.
error

Could you review the configuration settings in my mongod.cfg file, please?

# Where and how to store data.
storage:
  dbPath: C:\Program Files\MongoDB\Server\7.0\data
  directoryPerDB: true
  # storage.directoryPerDB: true

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path:  C:\Program Files\MongoDB\Server\7.0\log\mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


I do not know Windows.

The thing I know is that the directory mentioned as dbPath: must exist.

Thanks for your assistance.

If this involves distinct instances, I can create separate folders using different ports. However, my preference is to have it within the same instance.

Without the log it’s hard to see why it failed to start but the instructions said to stop the process, set that flag AND set the data folder to a new folder as opposed to the current one. Did you do that last step?

Changing the dbpath does not result in any errors. An error is only thrown if I include “directoryPerDB: true”.

If I modify the database path, it will affect all databases within the same instance. I want to change the directory for each database individually within a single instance.

So what does the log say, why does it fail to start?

This seems to do what you want, in principle. Set that flag, get the databases setup and then you can shut down and then add symbolic links etc to point to wherever you want on a drive.

As @steevej has already posted this link. There is some further reading on how to convert an existing deployment to using directoryPerDB under the option description.