Created
April 25, 2018 11:17
-
-
Save rahulkumar-aws/44f8e4d89b8a85ba27443fa024906141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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