I am trying to use kmongo
with kotlinx-datetime
. The data class looks like this:
@Serializable
data class CustomerCount(
@Contextual val _id: Id<CustomerCount>?,
val counter: Int,
@Contextual val date: LocalDateTime
) {
constructor(counter: Int): this(
null,
counter,
Clock.System.now().toLocalDateTime(TimeZone.of("Europe/Zurich"))
)
}
When I now try to save an instance of CustomerCount
to MongoDB I get the following error:
com.mongodb.MongoWriteException: Write operation error on server localhost:27017. Write error: WriteError{code=2, message=''date' must be present and contain a valid BSON UTC datetime value', details={}}.
How can I save kotlinx-datetime
objects to MongoDB?