Aymen Kanzari
Aymen Kanzari

Reputation: 2023

spring data mongodb: compare LocalDateTime query

I have the below object

@Document(collection = "qr_code")
public class QrCode implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String qrCodeId;

    @Field
    private String codePay;

    private LocalDateTime expiredIn;

}

I have this query to check if a codePay exists or not

boolean existsByCodePay(String codePay);

I want another query to check if a QrCode is expired or not, based on attribute expiredIn, that's to say the QrCode expired when expiredIn < LocalDateTime.now()

@Query(???)
boolean isQrCodeExpired(String codePay);

Upvotes: 0

Views: 420

Answers (1)

Mehedi Hasan Shifat
Mehedi Hasan Shifat

Reputation: 720

The raw mongodb query can be something like this :

{
    "expiredIn":{
        $gt : new Date()
    }
}

Upvotes: 1

Related Questions