Search code examples
quarkus-panache

Dynamic determination for database


I have some entity mapping to a collection in a mongoDB. However, I have a separate database I want the same code to run against (eg. Constants.db_B). How can I make this parameter dynamic so I can run this without changing the constant and recompiling? If I could pass this as a parameter that would be fine too.

@MongoEntity(collection = "sample", database = Constants.db_A)
public class SomeEntity extends PanacheMongoEntity {
}

I tried using ConfigProperty on the Constants class, but it only injects it on a bean instance and not the class itself.

Is this possible?


Solution

  • It's not possible right now. This has been issued in the quarkus project. https://github.com/quarkusio/quarkus/issues/14789

    It's not the same casuistry than yours but there's a solution made from the Author of that issue, may be helpful for you https://gitlab.com/ch3rub1/quarkus-mongo-mutitenant