2

I'm using Spring data with MongoDB and i need to find between actual day and 7 days ahead.

I have create repsoitories with @Query annotation and don't like to user Criteria class.

Do you have some idea how to user between with @Query?

thanks in advance.

s7vr
  • 73,656
  • 11
  • 106
  • 127

2 Answers2

5

You can try below query.

Using @Query annotation

@Query(value = "{'date':{ $lt: ?0, $gt: ?1}}")
List<SomeClass> findByDateBetween(Instant from, Instant to);

Or

Using repository supported keywords

List<SomeClass> findByDateBetween(Instant from, Instant to);
s7vr
  • 73,656
  • 11
  • 106
  • 127
0

You can try thquery.

@Query(value = "{'champsDate':{ $gte: ?0, $lte: ?1}}")
List<entity> findByChampsDateBetween(Date startDate, Date endDate);
Yousra ADDALI
  • 332
  • 1
  • 3
  • 14