Looking in other posts about how to make an optional parameter query with mongodb and parameters inpu as a list I found that it could be done with something like this:
@Query("{ $or : [ { $where: '?0 == null' } , { field : ?0 } ] }")
List<Something> findAll(String query, Pageable pageable);
My query looks like this:
@Query("{ $or : [ { $where: '?3 == null' } ,{ input1 : { $in : ?3 } }], 'input2' : ?4 , 'input3' : ?2 ,'dateInput' : {$gt : ?0, $lte : ?1}}")
List<Entities> findThingsbyInputs(Long initialDate, Long endDate, Integer Input2, List<Integer> input1, Integer input3);
When I use this query and Input1 = ?0 = ArrayList, it work nice if the list is not null, but when ?0 is null an exception is lauched. I can query several input parameters with the list but when null, it doesnt work.
The error message is: Query failed with error code 2 and error message '$in needs an array' on server localhost:27017
Any help? and Thanks in advance