Spring Data MongoDB query with multiple optional parameters $in Collection -
i have use case query need find based on 3 optional fields , 1 of them pass in collection.
the "3 optional fields" part solved post spring data mongodb and/or query multiple optional parameters
however, runnig issue $in
collection filed.
for example, in following query
{ $and : [{ $and: [ {$or : [ { $where: '?0 == null' } , { : ?0 }]}, {$or : [ { $where: '?1 == null' } , { b : ?1 }]}, {$or : [ { $where: '?2 == null' } , { c : ?2 }]} ] }] }
in case, field a
pass in collection, need find object in mongodb filed a
$in
collection passed in.
i have tried this
{ $and : [{ $and: [ {$or : [ { $where: '?0 == null' } , { : { $in : ?0 }}]}, {$or : [ { $where: '?1 == null' } , { b : ?1 }]}, {$or : [ { $where: '?2 == null' } , { c : ?2 }]} ] }] }
however, got npe when pass in null
collection.
you need test collection length, shown here spring-data-mongo - optional query parameters? can rid of top-level $and.
{ $and : [ {$or : [ { $where: '?0.length == 0' } , { : { $in : ?0 }}]}, {$or : [ { $where: '?1 == null' } , { b : ?1 }]}, {$or : [ { $where: '?2 == null' } , { c : ?2 }]} ] }
Comments
Post a Comment