简体   繁体   English

日期范围查询不起作用mongoDB

[英]Date Range Query not working mongoDB

I have UesrFeedback document as describe below with date and I wanted to find out all documents between start and end dates. 我有如下所述的UesrFeedback文档以及日期,我想找出开始日期和结束日期之间的所有文档。 I am not getting correct result I get result that is out of range from start and end dates. 我没有得到正确的结果,我得到的结果超出了开始日期和结束日期。

Here is document: 这是文件:

class UserFeedbackImpl{
    private String userId;
    @Indexed
    private String resourceId;
    @Indexed
    private String resoruceType;
    private String rating;
    private String comments;
    private Date creationTimeStamp = new Date();
}

MongoDB query: MongoDB查询:

public List<UserFeedback> findUserFeedback(Date Start, Date end){
    Query query = new Query(Criteria.where("creationTimeStamp").gte(Start).andOperator(Criteria.where("creationTimeStamp").lte(end)));
    List<UserFeedbackImpl> pref = getTemplate().find(query,UserFeedbackImpl.class);

Any help is greatly appreciated. 任何帮助是极大的赞赏。

I believe the andOperator takes in a list of Criteria as its parameters, so you'd want 我相信andOperator会将Criteria列表作为其参数,因此您需要

Query query = new Query(Criteria.andOperator( Criteria.where("creationTimeStamp").gte(Start), Criteria.where("creationTimeStamp").lte(end) ));

This is according to the spring documentation here: http://static.springsource.org/spring-data/data-mongo/docs/1.0.0.M5/api/org/springframework/data/mongodb/core/query/Criteria.html#andOperator(org.springframework.data.mongodb.core.query.Criteria ...) 这是根据此处的spring文档: http : //static.springsource.org/spring-data/data-mongo/docs/1.0.0.M5/api/org/springframework/data/mongodb/core/query/Criteria .html#andOperator(org.springframework.data.mongodb.core.query.Criteria ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM