2012-09-19 28 views
0

我有UesrFeedback文档,如下所述与日期,我想查找开始和结束日期之间的所有文档。我没有得到正确的结果,我得到的结果超出了开始和结束日期的范围。日期范围查询不起作用mongoDB

下面是文档:

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的查询:

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); 

任何帮助是极大的赞赏。

+1

有一个Mongo Cookbook关于此主题的文章:http://cookbook.mongodb.org/patterns/date_range/ – JohnnyHK

回答

3

我相信andOperator发生在标准作为其参数列表,以便

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

这是根据弹簧的文档在这里,你会想: 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 ......)