Vasu Youth
Vasu Youth

Reputation: 373

Spring Boot filter by multiple fields (MongoDB)

I've an API in springboot which gets the data from mongo DB. This API accepts 4 filters:

  1. From Date
  2. To Date
  3. Name
  4. Role

Now, the user can send any of the filters or all filters. Example, if he passes just name and role, I should filter the data by name and role ignoring date fields. If he sends all values, I should filter by all fields. If he sends just from date, I should filter by from date ignoring all fields.

Can someone help me with this plesae?

Thank you

Upvotes: 0

Views: 1093

Answers (1)

Saravanakrishnan Pk
Saravanakrishnan Pk

Reputation: 461

Try Specifications from Spring Data JPA.

Documentation link - https://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl/

Upvotes: 1

Related Questions