Very similar to this question: Check date between two other dates spring data jpa
However, I am attempting to do this with MongoDB and java.time.LocalDateTime
.
I have tried:
findAllByMetadataStartTimeBetween(start, end)
(works, but exclusive start/end)findAllByMetadataStartTimeGreaterThanEqual(start)
(works, but no end)However, when I try: findAllByMetadataStartTimeGreaterThanEqualAndMetadataStartTimeLessThanEqual(start,end)
I get the error: json can't serialize type : class java.time.LocalDateTime
Any idea why this particular combination throws this error, when the previous ones do not?
Try the below code. I am sure, works for inclusive
@Query("{'dateTime' : { $gte: ?0, $lte: ?1 } }")
List<YourObject> findByDateTimeBetween(Date from, Date to);
Spring data method signature below works for exclusive
public List<YourObject> findByDateBetween(Date from, Date to);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With