I was connecting to my MongoDB using MongoConnectionOptions
in reactivemongo version 0.15.x
. Now I updated to 0.20.11
.
The apply()
function of the MongoConnectionOptions
companion object is deprecated now. The deprecation warning says to use the constructor of MongoConnectionOptions
. Unfortunately this constructor is package-private.
I do not want to use the deprecated apply function mainly because my scala compiler options do not allow warnings. (And I really don't want to change this).
The official documentation only explains the deprecated version: http://reactivemongo.org/releases/0.1x/documentation/tutorial/connect-database.html
How can I still connect to the database using connection options?
The factory MongoConnectionOptions(..)
will be refactored in coming next major release 1.0.x.
Anyway, you can using .default
+ .copy(..)
:
import reactivemongo.api.MongoConnectionOptions
MongoConnectionOptions.default.copy(appName = "Foo")
Moreover, options can be prepared (from config file or programmatically) as URI string.
val host = "localhost"
val port = 27017
reactivemongo.api.MongoConnection.connect(s"mongodb://${host}:${port}")