Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rahulkumar-aws/44f8e4d89b8a85ba27443fa024906141 to your computer and use it in GitHub Desktop.
Save rahulkumar-aws/44f8e4d89b8a85ba27443fa024906141 to your computer and use it in GitHub Desktop.
In your Play application, you can use ReactiveMongo with multiple connection pools (possibly with different replica sets and/or different options), using the @NamedDatabase annotation.
Consider the following configuration, with several connection URIs.
# The default URI
mongodb.uri = "mongodb://someuser:somepasswd@localhost:27017/foo"
# Another one, named with 'bar'
mongodb.bar.uri = "mongodb://someuser:somepasswd@localhost:27017/lorem"
Then the dependency injection can select the API instances using the names.
import javax.inject.Inject
import play.modules.reactivemongo._
class MyComponent @Inject() (
val defaultApi: ReactiveMongoApi, // corresponds to 'mongodb.uri'
@NamedDatabase("bar") val barApi: ReactiveMongoApi // 'mongodb.bar'
) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment