1

I am trying to use Query Annotation in my mongodb repository to compare dates. I have drive and request collections. The requests contain one drive. If the date of drive is passed, the request is considered as expired. I try to find the expired requests. I just cannot do comparison on dates.

Drive:

@Document
public class Drive {

    @Id
    private String id;
    @DBRef
    private User driver;
    @DBRef
    private Car car;
    private Date date;
    private Point origin;
    private Point destination;
    private List<Point> waystationList;
    @DBRef
    private List<User> passengerList;
    private String notes;
    private int avaliableSeats;

Request:

@Document
public class PassengerRequest {

    @Id
    private String id;
    @DBRef
    private Drive drive;
    private Point origin;
    private Point destination;
    private String note;
    @DBRef
    private User passenger;

RequestRepository:

@Repository
public interface PassengerRequestRepository extends MongoRepository<PassengerRequest, String> {

    @Query("{'drive' : { 'date' : { '$lt': new Date() }}}")
    List<PassengerRequest> findExpiredRequests();

}
Eray Tuncer
  • 707
  • 2
  • 11
  • 31
  • U can solve the problem this answer -> [url](https://stackoverflow.com/a/43966715/3673767) But I also have such a problem. I need a solution with Listener in java. – Erdem Aydemir Jun 01 '20 at 14:42

0 Answers0