ReactiveMongo 0.11.9 throws连接到mongodb 3.0.4时没有可用的主节点

时间:2015-12-30 01:41:59

标签: scala reactivemongo

我只是有一个reactivemongo(版本:0.11.9)插入查询,如下所示,

class MongoInsertQuery extends Query {
  val DbName = "events-db"
  val CollectionName = "EventStream"

  val driver = new MongoDriver
  val connection = driver.connection(List("127.0.0.1:27018"))

    def insert() = {
        val db = connection(DbName)
        val collection: BSONCollection = db(CollectionName)
        val futureResult: Future[WriteResult] = collection.insert(BSONDocument("type" -> "Product_Received"))
        futureResult onComplete {
          case Success(s) => println("Success " + s)
          case Failure(e) => {
            println("error " + e.getMessage)
            e.printStackTrace()
          }
        }
      }
}

并不重要,但 Scala Play REST控制器会调用该方法

  def sayBeard = Action { request =>
    new MongoInsertQuery().insert()
    Ok(Json.obj("message" -> "TODO respond writeResult"))
  }

当我呼叫端点时,

$ curl -XGET localhost:9000/sayBeard
{"message":"TODO respond writeResult"}

成功插入mongodb 2.4.14

precise64(mongod-2.4.14) events-db> db.EventStream.find({})
{
  "_id": ObjectId("5683337120906c127504eb79"),
  "type": "Product_Received"
}

readAndDeserialize上的Failure错误导致future onComplete错误。

[info] - play.api.Play - Application started (Dev)
error 83
java.lang.ArrayIndexOutOfBoundsException: 83
    at org.jboss.netty.buffer.LittleEndianHeapChannelBuffer.getInt(LittleEndianHeapChannelBuffer.java:69)
    at reactivemongo.api.SerializationPack$class.readAndDeserialize(serializationpack.scala:31)
    at reactivemongo.api.BSONSerializationPack$.readAndDeserialize(serializationpack.scala:41)
    at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1$$anonfun$apply$12.apply(genericcollection.scala:279)
    at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1$$anonfun$apply$12.apply(genericcollection.scala:279)
    at scala.util.Success$$anonfun$map$1.apply(Try.scala:237)
    at scala.util.Try$.apply(Try.scala:192)
    at scala.util.Success.map(Try.scala:237)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    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.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我的目的是在插入Collection之后阅读writeResult上的WriteResultNmessage)。

使用mongo 3.0.6,它甚至找不到mongodb。

23:02:02.172 [ForkJoinPool-6-worker-9] ERROR reactivemongo.api.Failover2 - Got an error, no more attempts to do. Completing with a failure...
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$: MongoError['No primary node is available!']
    at reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.<clinit>(actors.scala) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at scala.Option.getOrElse(Option.scala:121) ~[scala-library-2.11.7.jar:?]
    at reactivemongo.core.actors.MongoDBSystem$class.reactivemongo$core$actors$MongoDBSystem$$pickChannel(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.core.actors.MongoDBSystem$$anonfun$4.applyOrElse(actors.scala:335) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170) ~[scala-library-2.11.7.jar:?]
    at akka.actor.Actor$class.aroundReceive(Actor.scala:467) ~[akka-actor_2.11-2.3.13.jar:?]
    at reactivemongo.core.actors.LegacyDBSystem.aroundReceive(actors.scala:796) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516) ~[akka-actor_2.11-2.3.13.jar:?]
    at akka.actor.ActorCell.invoke(ActorCell.scala:487) ~[akka-actor_2.11-2.3.13.jar:?]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) ~[akka-actor_2.11-2.3.13.jar:?]
    at akka.dispatch.Mailbox.run(Mailbox.scala:220) ~[akka-actor_2.11-2.3.13.jar:?]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[akka-actor_2.11-2.3.13.jar:?]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:?]

虽然,我看到连接登录mongo,

2015-12-30T23:21:57.688-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:51663 #11 (11 connections now open)

参考

http://reactivemongo.org/releases/0.11/documentation/tutorial/write-documents.html

https://groups.google.com/forum/#!topic/reactivemongo/0jxS1cgXjP8

1 个答案:

答案 0 :(得分:1)

所以,问题是reactivemongo 0.11.4支持mongodb 3.0+。然后我不得不更新mongodb主机。

  val driver = new MongoDriver
  val connection = driver.connection(List("127.0.0.1:27017"))

java.lang.ArrayIndexOutOfBoundsException on update with mongo 2.4.12 #394