-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java LocalTime read converter and write converter problem #3991
Comments
I write custom LocalTime converter classes to make "find" query correctly
|
Have you already tried using the driver native time codec? It can be enabled via If you have the time, it would be great it you could provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem. |
I have tried to use the default LocalTime converter. The problem is LocalTime is saved with current date. which the date should be fixed like LocalDate's time. |
Using the native java.time codecs by setting |
Hello
I have saved some time series data in a field type LocalTime.
When a LocalTime type field saved into MongoDB collection, it is saved as in MongoDB data type "date"
which is in the form of ISO Date. However, the date part and the time part are the compulsory of MongoDB data type "date"
so when LocalTime is saved, rubbish date part is included. Now the write converter put the rubbish date part is creation date
of the object.
For example, when "14:21:12" LocalTime is saved, MongoDB collection data is saved by the form "2022-03-01 14:21:12".
so far, there is no problem.
But when find by LocalTime for a field,
there is a problem.
If the spring application is running on different date to the creation of the MongoDB date field which the time information saved,
the MongoDB query generated with different date to the stored MongoDB date, so finding the time part of the date can't be matched which it should be founded.
For example,
on the date 2022-03-01
document -> { editDate: 2022-03-01 14:21:12 }
on the date 2022-03-02 finding the above document,
if I find "14:21:12", finding query is generated as "{editDate: ISODate('2022-03-02 14:21:12')}",
so the document can't be founded properly
Spring Data MongoDB should create a query "{editDate: ISODate('%%%%-%%-%% 14:21:12')}".
% means one digit number 0 to 9
Thank you.
The text was updated successfully, but these errors were encountered: