1

I have a spring mongo repository with the following method

@Query(value = "{'topicId':{$in: ?0},'ts':{$gt:{$date:?2}, $lte:{$date:?3}}, 'status': {$ne:?4}, 'seen':?1 }")
    public Page<NotificationReference> findByTopicIdInAndSeenAndStatusNot(List<String> topicIds, Boolean seen,
            Date from, Date to, String status, Pageable pageable);

But the ?2 and ?3 date variables are not resolving to their values. I'm passing a java.util.Date to the method, how do I get spring to resolve date variables for mongo queries?

2
  • 1
    Have you tried to ommit the $date keywords? I mean something like this: @Query(value = "{'topicId':{$in: ?0},'ts':{$gt:?2}, $lte:?3}}, 'status': {$ne:?4}, 'seen':?1 }") Commented Aug 9, 2016 at 20:02
  • That worked thank you Commented Aug 9, 2016 at 20:07

1 Answer 1

1

Not using $date should be enough.

 @Query(value = "{'topicId':{$in: ?0},'ts':{$gt:{$date:?2}, $lte:{$date:?3}}, 'status': {$ne:?4}, 'seen':?1 }")
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.