【问题标题】:Scala mongodb driverScala MongoDB 驱动程序
【发布时间】:2018-05-03 12:02:19
【问题描述】:

插入工作正常。问题在于 find()

对于 find(),

val collection: MongoCollection[Machine] =    mongoDB.getCollection(DbConstants.COLLECTION_NAME_MACHINE)

collection.find().subscribe(new Observer[Machine] {

  override def onNext(result: Machine): Unit = println(s"Machine is $result")

  override def onError(e: Throwable): Unit = e.printStackTrace()

  override def onComplete(): Unit = println("Completed")
})

显示错误:

org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is OBJECT_ID.

机器的数据模型是:

case class Machine(_id: String,
    @BsonProperty(DbConstants.FIELD_SITE_ID)siteId: BsonObjectId)

以下教程来自: http://mongodb.github.io/mongo-scala-driver/2.2/getting-started/quick-tour-case-classes/

【问题讨论】:

    标签: mongodb scala mongo-scala-driver


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 2017-06-05
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多