kmongo
kmongo copied to clipboard
[Feature] Support kotlinx.datetime values
I am using kmongo on a multiplatform project, which necessarily uses kotlinx.datetime for the datamodel since java.time.* are not multiplatform.
It would be great if kotlinx.datetime was supported for serializing date/times by default.
Not sure how similar this is, but I've been trying to use mongo 5.0 time-series collections, with kotlinx.serialization and kotlinx.datetime. In a regular collection I can use kotlinx.datetime with no issue but if I try to use it for the time series field of a time series collection I get the following error : WriteError{code=2, message=''timestamp' must be present and contain a valid BSON UTC datetime value', details={}}
This would help a lot.
Seems like kotlinx.serialization serializes dates to strings, therefore I have the same problem on timeseries as @cholwell and when there is data in a collection with dates, I get the following Error when loading the data:
readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DATE_TIME.
I just implemented serialization for kotlinx.datetime Instant, LocalDate, LocalDateTime and LocalTime and made a pull-request. The serialization works for normal collections, as well as for time-serie collections.
Are there other serializations needed from kotlinx.datetime?
Thank you! I'm going to review the PR