Mongodb 今天找到';在mongorepository或Mongooperations或mongotemplate中使用spring数据@Query设置日期

Mongodb 今天找到';在mongorepository或Mongooperations或mongotemplate中使用spring数据@Query设置日期,mongodb,spring-data,mongotemplate,mongorepository,Mongodb,Spring Data,Mongotemplate,Mongorepository,我正在尝试使用mongorepository或mongooperations或mongotemplate从mongodb中获取今天创建的所有记录。我只想按日期匹配所有记录,而不是按时间戳匹配。请参考下面我的mongodb条目 /* 1 */ { "_id" : ObjectId("59135f13fc90f22b00c91df2"), "_class" : "com.vistors.management.domains.EmployeeVisitor", "checkedIn" : true,

我正在尝试使用mongorepository或mongooperations或mongotemplate从mongodb中获取今天创建的所有记录。我只想按日期匹配所有记录,而不是按时间戳匹配。请参考下面我的mongodb条目

/* 1 */
{
"_id" : ObjectId("59135f13fc90f22b00c91df2"),
"_class" : "com.vistors.management.domains.EmployeeVisitor",
"checkedIn" : true,
"checkedInDate" : ISODate("2017-05-10T18:42:27.630Z"),
"visitor" : {
    "$ref" : "VISITOR",
    "$id" : ObjectId("59135f13fc90f22b00c91def")
},
"employee" : {
    "$ref" : "EMPLOYEE",
    "$id" : ObjectId("59135f13fc90f22b00c91df0")
}
}

/* 2 */
{
"_id" : ObjectId("59135f13fc90f22b00c91df3"),
"_class" : "com.vistors.management.domains.EmployeeVisitor",
"checkedIn" : true,
"checkedInDate" : ISODate("2017-05-10T18:42:27.638Z"),
"visitor" : {
    "$ref" : "VISITOR",
    "$id" : ObjectId("59135f13fc90f22b00c91dee")
},
"employee" : {
    "$ref" : "EMPLOYEE",
    "$id" : ObjectId("59135f13fc90f22b00c91df0")
}
}

/* 3 */
{
"_id" : ObjectId("5913ec9eafeb7a1e8df79d5f"),
"_class" : "com.vistors.management.domains.EmployeeVisitor",
"checkedIn" : true,
"checkedInDate" : ISODate("2017-05-11T04:46:22.425Z"),
"visitor" : {
    "$ref" : "VISITOR",
    "$id" : ObjectId("59135f13fc90f22b00c91dee")
},
"employee" : {
    "$ref" : "EMPLOYEE",
    "$id" : ObjectId("59135f13fc90f22b00c91df0")
}
}
我想从db获取所有与CheckedDate匹配的条目,如今天的日期:

@Query("{'checkedInDate': {$gte: ?0, $lte:?0 }}")
List<EmployeeVisitor> findAllCheckedInToday(ZonedDateTime date)
@Query(“{'checkedDate':{$gte:?0,$lte:?0}”)
列出findAllCheckedInToday(ZonedDateTime日期)

@覆盖
公共列表getTodayRecords(){
//日期=开始日期(即时);
Query Query=new Query().addCriteria(Criteria.where(“checkedDate”).is(new Date());
返回mongoTemplate.find(查询,EmployeeVisitor.class);
//条件。其中(“expenseDate”).gte(calendar1.getTime()).lte(calendar2.getTime())和(“userid”).is(uid);}
}
但是我没有达到所需的结果,我无法理解如何从带有日期而不是带有时间戳的日期的数据库中查询

谢谢你的帮助


Jitender继续@Veeram的建议。这就是你能做的

ZonedDateTime today = ZonedDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT, ZoneId.systemDefault());
ZonedDateTime tomorrow = today.plusDays(1);  
repository.finByCheckedInDateBetween(Date.from(today.toInstant()), Date.from(tomorrow.toInstant()));  
您可以将存储库方法更改为类似这样的方式

finByCheckedInDateBetween(Date from, Date to)

您可以将存储库方法更改为以下内容:

List<EmployeeVisitor> findByCheckedInDate(ZonedDateTime date)
List findByCheckedInDate(ZonedDateTime日期)

Oh。。是的,这很好用,谢谢你和Veeram
List<EmployeeVisitor> findByCheckedInDate(ZonedDateTime date)