我正在尝试通过spring-data-mongodb / data-rest标准存储库实现简单的日期搜索。我有一个方法的课程:
@RepositoryRestResource
public interface PersonRepository extends MongoRepository<Person, String> {
List<Person> findByDateUpdatedBetween(@Param("fromDate") Date fromDate, @Param("toDate") Date toDate);
}
如果没有提供第二个参数,这里是如何工作的:
{ "dateUpdated" : { "$gt" : { "$date" : "2016-02-13T05:41:38.000Z"} , "$lt" : null }}
有没有办法让它没有第二个参数?这是一个正确的行为吗?
我试图用这样的自定义查询来标记它:
@Query("{ 'dateUpdated' : { '$gt' : { '$date' : ?0} , '$lt' : {'$cond' : { if: { ?1 : {'$ne' : null} }, then: '$currentDate', else: ?1 }} }}")
但没有运气:
2016-02-14 21:45:47 [http-nio-8091-exec-1] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod.invokeForRequest(139) - Method [errorHtml] returned [ModelAndView: reference to view with name 'error'; model is {timestamp=Sun Feb 14 21:45:47 WITA 2016, status=500, error=Internal Server Error, exception=com.mongodb.util.JSONParseException, message=
{ 'dateUpdated' : { '$gt' : { '$date' : ?0} , '$lt' : {'$cond' : { if: { null : {'$ne' : null} }, then: '$currentDate', else: null }} }}
^, path=/persons/search/findByDateUpdatedBetween}]