I have a use case where my query need to find based on 3 optional fields and one of them is pass in as a collection.
The "3 optional fields" part is already solved by this post Spring Data MongoDB AND/OR query with multiple optional parameters
However, I am runnig into the issue with the $in
for the collection filed.
For example, in the following query
{ $and :
[{
$and:
[
{$or : [ { $where: '?0 == null' } , { a : ?0 }]},
{$or : [ { $where: '?1 == null' } , { b : ?1 }]},
{$or : [ { $where: '?2 == null' } , { c : ?2 }]}
]
}]
}
In my case, the field a
is actually pass in as a collection, I need to find those object in MongoDB with filed a
is $in
the collection I passed in.
I have tried with something like this
{ $and :
[{
$and:
[
{$or : [ { $where: '?0 == null' } , { a : { $in : ?0 }}]},
{$or : [ { $where: '?1 == null' } , { b : ?1 }]},
{$or : [ { $where: '?2 == null' } , { c : ?2 }]}
]
}]
}
However, I got NPE for this when I pass in a null
collection.