2

I have two Docker containers:

  1. Running MongoDB
  2. 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.

Community
  • 1
  • 1
thwiegan
  • 2,163
  • 10
  • 18
  • 1
    Last time I had this, I was logging into the DB with a user that had the wrong credentials IIRC. – Jean-Philippe Pellet Apr 11 '16 at 20:34
  • Use `connection.database(..)` instead of `connection(..)` (or of its alias `connection.db(..)`), to have proper DB resolution.You should have a deprecation warning. – cchantep Apr 11 '16 at 20:44
  • @Jean-PhilippePellet Thanks a lot, that did the trick! My Docker script is supposed to create the users, but apparently they don't get created.. Still weird that I can read, even though the user I am trying to authenticate with does not exist. And the error message is more than misleading.. – thwiegan Apr 12 '16 at 09:58
  • You should have a compilation warning indicating that `.db` is deprecated (due to its sync issue). – cchantep Apr 13 '16 at 07:28

0 Answers0