Quarkus: MongoDB ReadPreferences Configuration per collection

Created on 22 Jul 2020  路  8Comments  路  Source: quarkusio/quarkus

MongoDB official driver offers the ability to specify _ReadPreferences_ per collection. It would be helpful to have this option in Quarkus Driver for MongoDB too.

aremongodb good first issue

Most helpful comment

There is two ways it can be done.

  1. create an annotation like @ReadPreferences. Then update MongoOperations to read them from the entity class and use them where needed.
  2. allow to specify it only for PanacheQuery with a method like .readPreference(), it will allow to specify read preferences per request and not per collection and will mandates the user to use the .find() operation but it'll be easier to implement.

@evanchooly WDYT is the best way to specify read preferences, should we add an entity level annotation or only allow to customize it at query time ?

All 8 comments

/cc @loicmathieu

It would be helpful to have this option in Quarkus Driver for MongoDB too.

You can already define it at the client level inside the quarkus-mongodb-client extension configuration.

If you mean, to have a way to configure it by collection via MongoDB with Panache, I agree this is a good enhancement.

@loicmathieu Could you help with where to start on this issue and give more details?

There is two ways it can be done.

  1. create an annotation like @ReadPreferences. Then update MongoOperations to read them from the entity class and use them where needed.
  2. allow to specify it only for PanacheQuery with a method like .readPreference(), it will allow to specify read preferences per request and not per collection and will mandates the user to use the .find() operation but it'll be easier to implement.

@evanchooly WDYT is the best way to specify read preferences, should we add an entity level annotation or only allow to customize it at query time ?

Having inherited something similar in Morphia, I definitely lean toward the query option. Such options rarely apply generically across all uses of an entity and benefit more from a targeted application in specific use cases.

This is also the easiest way to implement this ;)
@ShqiprimBunjaku will having a way to specify read preferencies per query fit your needs ?

Yes that would work. But I suggest to specify per collection and if specified per query to override the collection's read preferences.
I see that you are implementing this in MongoDB with Panache, can this also be implemented in Quarkus Reactive Mongo Client with Mutiny?

@shqiprimbkodelabs this will be implemented inside the Quarkus Reactive Mongo Client as it's needed to implement it inside MongoDB with Panache.

Was this page helpful?
0 / 5 - 0 ratings