我有这个案例类:
case class CodeRegister(id: String, name: String, code: Option[CodeData])
case class CodeData(code: String, expiry: Long)
我已经通过方法注册了CodeRegister
两者。现在我尝试使用此代码更新该字段CodeData
fromProviders
code
collection.updateOne(equal("id",record. id),
set("code", record.code)).
toFutureOption()
但是,我有这个错误
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class scala.Some.
at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:37)
at com.mongodb.client.model.Updates$SimpleUpdate.toBsonDocument(Updates.java:445)
at com.mongodb.client.model.Updates$CompositeUpdate.toBsonDocument(Updates.java:614)
at com.mongodb.internal.operation.Operations.toBsonDocument(Operations.java:489)
at com.mongodb.internal.operation.Operations.bulkWrite(Operations.java:369)
at com.mongodb.internal.operation.Operations.updateOne(Operations.java:318)
at com.mongodb.internal.operation.AsyncOperations.updateOne(AsyncOperations.java:168)
at com.mongodb.async.client.MongoCollectionImpl.executeUpdate(MongoCollectionImpl.java:702)
at com.mongodb.async.client.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:659)
at com.mongodb.async.client.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:653)
at org.mongodb.scala.MongoCollection.$anonfun$updateOne$1(MongoCollection.scala:861)
at org.mongodb.scala.MongoCollection.$anonfun$updateOne$1$adapted(MongoCollection.scala:861)
at org.mongodb.scala.internal.ObservableHelper$$anon$1.apply(ObservableHelper.scala:36)
at org.mongodb.scala.internal.ObservableHelper$$anon$1.apply(ObservableHelper.scala:35)
at com.mongodb.async.client.SingleResultCallbackSubscription.requestInitialData(SingleResultCallbackSubscription.java:38)
at com.mongodb.async.client.AbstractSubscription.tryRequestInitialData(AbstractSubscription.java:151)
at com.mongodb.async.client.AbstractSubscription.request(AbstractSubscription.java:84)
at org.mongodb.scala.ObservableImplicits$BoxedSubscription.request(ObservableImplicits.scala:490)
at org.mongodb.scala.ObservableImplicits$ScalaObservable$$anon$2.onSubscribe(ObservableImplicits.scala:366)
at org.mongodb.scala.ObservableImplicits$ToSingleObservable$$anon$3.onSubscribe(ObservableImplicits.scala:441)
at org.mongodb.scala.internal.SubscriptionCheckingObserver.onSubscribe(SubscriptionCheckingObserver.scala:28)
at org.mongodb.scala.Observer.onSubscribe(Observer.scala:85)
at org.mongodb.scala.Observer.onSubscribe$(Observer.scala:85)
at org.mongodb.scala.internal.SubscriptionCheckingObserver.onSubscribe(SubscriptionCheckingObserver.scala:21)
at com.mongodb.async.client.SingleResultCallbackSubscription.<init>(SingleResultCallbackSubscription.java:33)
at com.mongodb.async.client.Observables$2.subscribe(Observables.java:78)
at org.mongodb.scala.ObservableImplicits$BoxedObservable.subscribe(ObservableImplicits.scala:474)
at org.mongodb.scala.ObservableImplicits$ToSingleObservable.subscribe(ObservableImplicits.scala:433)
at org.mongodb.scala.ObservableImplicits$ScalaObservable.headOption(ObservableImplicits.scala:358)
at org.mongodb.scala.ObservableImplicits$ScalaSingleObservable.toFutureOption(ObservableImplicits.scala:419)
我已经通过添加和添加新的匹配条件来尝试此链接中的解决方案,SomeCodec
CodeData
case Some(v: CodeData) => {
writer.writeStartDocument()
writer.writeString(v.code)
writer.writeInt64(v.expire)
writer.writeEndDocument()
}
但我有这个错误
org.bson.BsonInvalidOperationException: writeString can only be called when State is VALUE, not when State is NAME
现在,我不知道下一步该怎么做。任何帮助表示赞赏。