Skip to content
Advertisement

How to get list of data containing count of a field using Aggregation and Criteria in Spring Boot with MangoDB

Requirement: documents-bookdata collection may have multiple objects with same bookPublisherName but different bookName. Means multiple books can have same publisher so need to extract count of books per publisher .

Model class:

JavaScript

Response format pojo

JavaScript

Response Format

JavaScript

Advertisement

Answer

This requirement can also be done logically ..like get the list of DocumentsBookdata using findAll and than filter it using loop and store the count for books per publisher.But that would be a lengthy approach.SO below code will simply use Aggregation to get the book cout per publisher

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement