Reputation: 137
Im trying to save List< LocalDate > in mongo (just the date without time in yyyy-MM-dd format), After my API completes the calculation of datesList , im trying to save those dates in MongoDB. Upon saving ,i see that the dates are being saved in yyyy-MM-dd hh:mm:ss format as shown below.
Can someone let me know why is this happening? Is there a way to just save the LocalDate in yyyy-MM-dd format? Thank you so much.
Im using SpringJPA Mongo with springboot and Java.
Upvotes: 6
Views: 4905
Reputation: 28356
This is happening because MongoDB stores data in BSON format (see the BSON spec).
There is no datatype in BSON for Date
, there is only Timestamp
and UTC Datetime
both of which are stored as a 64-bit integer. UTC datetime is the number of milliseconds since epoch, leading to the time portion being all zeroes when it is rendered.
If you want to store just the date, you'll need to use a string type.
If the issue is how the data is displayed, you'll just need a different function to convert the timestamp returned from MongoDB to the display format you want to use.
Upvotes: 9