简体   繁体   English

Scala mongodb驱动程序

[英]Scala mongodb driver

Insertion is working fine. 插入工作正常。 Problem is with find() 问题出在find()

For 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")
})

It shows Error: 它显示错误:

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

In data model for Machine is: 在Machine的数据模型中是:

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

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

You may have null values in the data and that is causing the issue. 您的数据中可能包含空值,这就是导致问题的原因。

Exception when geting distinct values of a field from Mongo collection using mongo Java Driver 3.0 使用mongo Java Driver 3.0从Mongo集合中获取字段的不同值时发生异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM