简体   繁体   English

Mongo-Scala-Driver:CodecConfigurationException:找不到类immutable.Document的编解码器

[英]Mongo-Scala-Driver: CodecConfigurationException: can't find a codec for class immutable.Document

Error message: 错误信息:

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.mongodb.scala.bson.collection.immutable.Document

Code: 码:

def queueWrite(collection: String, filter: Map[String, () => String], data: Map[String, () => String]) {
    val col = collections.get(collection).get

    val filterBson = Document()
    filter.foreach(f => { filterBson.append(f._1, f._2.apply) })

    val dataBson = Document()
    data.foreach(f => { dataBson.append(f._1, f._2.apply) })

    val options = new FindOneAndUpdateOptions
    options.returnDocument(ReturnDocument.AFTER)
    options.upsert(true)

    val observer = new Observer[Document] {
      override def onNext(doc: Document) = println(doc.toJson)
      override def onError(e: Throwable) = e.printStackTrace
      override def onComplete = println("onComplete")
    }

    val observable: Observable[Document] = col.findOneAndUpdate(filterBson, dataBson, options)
    observable.subscribe(observer)

  }

Called with: 叫:

val filter = Map[String, () => String]("uuid", p.getUniqueId.toString)

var dataMap = Map[String, () => String]()
dataMap = dataMap.+("uuid" -> p.getUniqueId.toString)
dataMap = dataMap.+("nickname" -> p.getDisplayName)

queueWrite("players", filter, dataMap)


I've tried using mutable documents but then realized that findoneandupdate returns an immutable. 我尝试过使用可变文档但后来意识到findoneandupdate返回一个不可变的文件。 I also tried using a BsonDocument for the filter with equal but that ofc had no effect. 我也尝试使用BsonDocument过滤器,但是ofc没有效果。 I'm not really sure where to go from here, any help would be greatly appreciated :) 我不确定从哪里开始,任何帮助都会非常感激:)

private val settings = MongoClientSettings.builder
    .clusterSettings(clusterSettings)
    .build

My MongoClientSettings looked like this before, I needed to change it to this: 我的MongoClientSettings之前看起来像这样,我需要将它更改为:

private val settings = MongoClientSettings.builder
    .clusterSettings(clusterSettings)
    .codecRegistry(MongoClient.DEFAULT_CODEC_REGISTRY)
    .build

It seems mongo didn't assume default codec registry 似乎mongo没有假设默认编解码器注册表

Thanks to @Ross for the help! 感谢@Ross的帮助!

暂无
暂无

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

相关问题 找不到我的课程的编解码器(CodecConfigurationException) - Can't find a codec for my class (CodecConfigurationException) mongo-operations spring mongo批量操作执行异常(CodecConfigurationException:找不到类的编解码器) - mongo-operations spring mongo bulk opeartion execution exception (CodecConfigurationException: Can't find a codec for class) Scala 错误:org.bson.codecs.configuration.CodecConfigurationException:找不到类 scala.Some 的编解码器 - Scala error: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class scala.Some spring-boot 2.1.0 mongo-CodecConfigurationException:找不到类java.time.Year的编解码器 - spring-boot 2.1.0 mongo - CodecConfigurationException: Can't find a codec for class java.time.Year Morphia - CodecConfigurationException:找不到类的编解码器 - 但类已注册 - Morphia - CodecConfigurationException: Can't find a codec for class - But class is registered CodecConfigurationException在MongoDB中找不到DateTime的编解码器 - CodecConfigurationException Can't find a codec for DateTime In MongoDB mongo-scala驱动程序交易示例 - Example of mongo-scala-driver transaction mongo-scala驱动程序是否支持GridF? - Does mongo-scala-driver support GridFs? org.bson.codecs.configuration.CodecConfigurationException:找不到类[Ljava.lang.String; - org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.String; org.bson.codecs.configuration.CodecConfigurationException:找不到类org.springframework.data.mongodb.core.query.GeoCommand的编解码器 - org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.springframework.data.mongodb.core.query.GeoCommand
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM