I want to write a mongodb query using spring data repository @Query annotation and here is my requirement:
Get all the Vins that were added in the last sixty minutes and they are still active
"keepAlive" is the time in milliseconds a particular VIN is active. When a record is entered in database, "keepAlive" can be set as 30 minutes, 60 minutes etc
Example data:
{ vin: "ANBCDERGGGHHGUTY", keepAlive: "3600000", dateAdded: "2019-12-16T16:45:29-05:00" } { vin: "T5765ERGGGHHGUTX", keepAlive: "1800000", dateAdded: "2019-11-14T13:41:29-03:00" }
Here are my classes:
public class MyEntity {
private String vin;
private long keepAlive;
private Date dateAdded;
}
I have tried something like this but it doesn't seem to work:
@Query(value = "{'keepAlive':{$lte : {$subtract: [?0, 'dateAdded']}}}")
List<MyEntity> findLatestVins(Date currentSystemDate);
Any idea how can I do this?