1
I have this query in my api:
@Query("{$and: ["
+ "{'online': ?5}, "
+ "{'locations.appointmentTimeRanges.weekday': ?6}, "
+ "{'specialties.name': ?7}, "
+ "{'healthInsurances.name' : ?8}"
+ "]}")
I need that when passing the parameters, when no field comes filled should disregard certain filter.
Example: It came as parameter only the online and weekday, the way it is looking also for Specialties.name and healthInsurances.name as empty and does not find anything.
I want at both times it looks for all attributes together or for some sent by the client, ignoring filter in which the parameter did not come filled. As in my example did not come Specialties.name and healthInsurances.name I want to ignore them in the search.
I hope you understand my question.
I think the way is around here
– Wallace Maxters
Are you using some backend?
– Wallace Maxters
Wallace I’m using Java (Spring JPA)
– Gabriela Mendonça
tries as follows: "{'online': ? 5 || { $exists: true } }, "
– thxmxx
Solved with $Where guys. {$or : [{'Specialties.name': { '$regex': ? 2, $options: 'i'}}, { $Where: '?4' }]} uses $or and it only performs the filter of that query line if '?4' is true, which is a Boolean field that I pass by parameter.
– Gabriela Mendonça
If you solved the problem, post the solution as the answer. No need to change the title.
– Woss