I am developing an application (on Java) that works with files on an external hard drive. There is also a Mongo database. I want the database to be on an external hard disk (in the same place as the files) and the program can work with it on "any" computer to which this disk was connected.

Tell me, please, how can I specify the path to the database files when connecting to it?

Now I connect to the database like this:

mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017")); database = mongoClient.getDatabase("baseName"); 

but in this case, the mongo independently determines the storage location of the database.

  • Usually such things are the setting of the DBMS itself, here is the answer how to change the cofig or set your own stackoverflow.com/questions/12738322/… - cache
  • Thanks, but as I understand it, in this case all the databases are transferred to a new location and on each computer you need to reconfigure the config (( - Wsl_F
  • Right. In advance, you cannot know, for example, how the carrier is mounted into the system (for example, what kind of disk) - and this is another way. If you want a portable database - look towards the embedded database - Chubatiy

0