Reputation: 670
I have UesrFeedback document as describe below with date and I wanted to find out all documents between start and end dates. 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:
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.
Upvotes: 0
Views: 2399
Reputation: 861
I believe the andOperator takes in a list of Criteria as its parameters, so you'd want
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...)
Upvotes: 3