[Play Java 2.2.3 - Mongo] Is is possible to switch database name at runtime?

38 views
Skip to first unread message

shrike71

unread,
Aug 25, 2014, 6:28:13 AM8/25/14
to mongo-jack...@googlegroups.com
Hi all,

Quick question... I've tried different ways of doing it but I can't seem to be able to do it without reverting to the standard Java driver for Mongo.

I'm building (or trying to...) a multi-tenanted application that sandboxes each customer (tenant) by their own Mongo database, as it seems considerably better and far less unwieldy than using prefixed collection names in one great big database. Is there a way in the mongo-jackson-mapper to alter the source database name as the base reference prior to invoking a getCollection()? I can't seem to find reference to a setDB(), setDatabase(), setConfig(), etc. anywhere. I think i'm just looking in the wrong place or misinterpreting the documentation.

I'm setting up DAOs using the standard approach recommended in the documentation after configuration in the application.conf file:

something like:

private static JacksonDBCollection<Category, String> coll = MongoDB.getCollection("brand", Category.class, String.class);

with a config of:

mongodb.database="vendor"
mongodb.servers="x.x.x.x:27017"


which i've had no problems with using a single database. However, since there now could be many databases, i need to load the database name dynamically based on login identity, so having an array of datasource configs in a file is not really an option.

Thanks in advance,

Shrike71

D G

unread,
Oct 9, 2014, 7:11:44 PM10/9/14
to mongo-jack...@googlegroups.com
Hello,

Did you find any solutions about this i have exactly the same need.

Thanks
Reply all
Reply to author
Forward
0 new messages