Spring数据mongo @Query绑定日期

时间:2016-08-09 19:34:27

标签: java spring mongodb spring-data

我有一个spring mongo存储库,其中包含以下方法

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

但是?2和?3日期变量没有解析为它们的值。我正在将java.util.Date传递给方法,如何让spring解决mongo查询的日期变量?

1 个答案:

答案 0 :(得分:1)

不使用$ date就足够了。

 @Query(value = "{'topicId':{$in: ?0},'ts':{$gt:{$date:?2}, $lte:{$date:?3}}, 'status': {$ne:?4}, 'seen':?1 }")
相关问题