I have two Docker containers:
- Running MongoDB
- Service using ReactiveMongo to connect to said MongoDB
The code I use to connect to the MongoDB:
trait MongoHelper {
this: BaseConfig =>
val dbKey: String
val collKey: String
lazy val mongoConfig = persistenceConfig.getConfig( dbKey )
lazy val servers = persistenceConfig.getStringList( s"$dbKey.servers" ).asScala
lazy val database = persistenceConfig.getString( s"$dbKey.database" )
lazy val username = persistenceConfig.getString( s"$dbKey.username" )
lazy val password = persistenceConfig.getString( s"$dbKey.password" )
lazy val credentials = Seq( Authenticate( database, username, password ) )
lazy val conOpts = MongoConnectionOptions( authSource = Some( database ), authMode = ScramSha1Authentication )
lazy val driver = new MongoDriver
lazy val connection = driver.connection( servers, authentications = credentials, options = conOpts )
lazy val db = connection( database )
}
The connection seems to be fine, since I can read from it without a problem. But as soon as I try to insert or update a document I hit the following exception:
reactivemongo.core.errors.ConnectionNotInitialized: MongoError['Connection is missing metadata (like protocol version, etc.) The connection pool is probably being initialized.']
at reactivemongo.core.errors.ConnectionNotInitialized$.MissingMetadata(errors.scala:71)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1.apply(genericcollection.scala:338)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1.apply(genericcollection.scala:314)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
But this makes no sense to me, the connection pool must be initialized, since I am using it to read from the database.