Instant should persist the same way (BsonType.DATE_TIME) as LocalDateTime and Date#15111
Conversation
matrei
left a comment
There was a problem hiding this comment.
LGTM! Good catch!
However, how will this effect existing applications using grails-data-mongodb?
Should we document that the field type in the database must be updated when people upgrade?
jdaugherty
left a comment
There was a problem hiding this comment.
My only concern with this is the upgrade guide was not updated to mention this change.
@matrei If anyone out there is actually using Instant, it will thrown an exception. The data must be fixed. Fortunately, there is an easy mongosh solution which I posted in UPGRADE7.md
done and a mongosh update example was provided. |
results in inconsistent mongo storage.
Spring Data persists Instant the same way as Date. So for mongodb it is stored as a BSON DateTime (displayed as ISODate(...)). That’s the correct and expected mapping. Grails, however, stores it as a Long.
Aggregation stages or queries that expect date types:
$year, $month, $week, $dayOfWeek
$dateTrunc, $dateAdd, $dateSubtract
$dateToString, $dateFromParts
so none of this works with the current Instant > Long implementation
Similar to Spring Data, the following should be interchangeable without requiring a database update: