Multidatabase options

48 views
Skip to first unread message

Vlad Pop

unread,
Aug 17, 2017, 8:26:05 AM8/17/17
to RestExpress
We need to partition our data into multiple databases, stored on different disks. Is there any way to do this in RestExpress?


The only solution I see is to have multiple MongoConfig objects, one for each database. However that nneds a new MongoClient for each database with it's own thread pool of connections. I would rather have one thread pool and somehow just switch between databases.

Would it work if I would just reuse the same MongoClient and just specify a different db name in the repository?

Todd Fredrich

unread,
Aug 18, 2017, 12:20:41 PM8/18/17
to RestExpress
Hi Vlad,

The MongoConfig class uses MongoClientURI (see: http://api.mongodb.com/java/current/com/mongodb/MongoClientURI.html) to parse the Mongo URI in the properties file--which already has the database name in it. I'm not sure what your options are unless you were to override MongoConfig or create your own that allows multiple URIs. I haven't looked into the MongoClient class to see what flexibility it has there either. But the repository would still be wired to a single database--you'd probably have to do the repository selection at a higher level in your api.

Wondering about the pressure to use multiple DBs as MongoDB already supports the idea of 'sharding' to different clusters--which would store different data on different disks. You'd just have to have a shard-key and use mongos (vs mongod) to enable that.

Anyway, I'm sorry I'm not of much help here... I'll be interested to hear where you end up.

Thanks,
--Todd
Reply all
Reply to author
Forward
0 new messages