collection.updateOne(Filters.eq("foo", "hello"), Updates.set("bar", List("A", "B", "C")))
I got exception when running it:
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class scala.collection.immutable.$colon$colon.
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:35)
at com.mongodb.client.model.Updates$SimpleUpdate.toBsonDocument(Updates.java:442)
...
I had tried changing the List to Array or other collection type, got same result.
The only solution that I know to work is by using Document object:
val updateDoc = Document("$set" -> Document("bar" -> List("A", "B", "C")))
collection.updateOne(Filters.eq("foo", "hello"), updateDoc)
But it looks verbose.
Is Updates.set doesn't work with collection value or have I missed something here?