spring-projects / spring-projects/spring-data-mongodb
Java LocalTime read converter and write converter problem
@sxhinzvc is already working on this.
Since Aug 23, 2023.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.