How to create complex custom query with mongo template

Hi!

Im using Java 8 and Spring, trying to create a query with mongo template.

I have this 3 collections:

public class User {     
    private String id;     
    private String catalogId;  
    private String name;  
    private String info;  
} 
 
public class Catalog {     
    private String id;     
    private String userId;     
    private boolean exist; 
} 

public class Item {     
    private String id;    
    private String catalogId;    
    private String userId; 
} 

I want to create a query that returns the following:

class Response {
  private User user;
  private int countOfCatalogs;
  private int countOfItems;
}

The idea is to return a list with that information for each user and the count of catalogs and items of each user, a List<Response. With pagination and sorting on ‘countOfCatalogs’ and ‘countOfItems’.

Is there a way to do something like this with Mongo template?

Thanks!