0

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.

1

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.