У меня есть этот класс дел:
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
Теперь,Я не знаю, как делать дальше.Любая помощь приветствуется.