My Aggregation Query skip,order is not working propery with java

148 views Asked by At

Here is my Java code. skip missing some records. also order is not working.

AggregateIterable<Document> propertiesDoc = collection.aggregate(Arrays.asList(
                    Aggregates.match(queryNew),
                     Aggregates.group("$similarGroup", Accumulators.sum("count", 1),Accumulators.first("data", "$$ROOT")),
                     Aggregates.skip(skipCount),
                    Aggregates.limit(searchRequest.getItemsPerPage()),
                    Aggregates.sort(descending("salePrice")))
                    );
1

There are 1 answers

0
Lavan Giri On

I found solution. there was multiple issues.

  1. there was some records missing the field "similarGroup".
  2. Sort was not working properly, and below code worked.

AggregateIterable propertiesDoc = collection.aggregate(Arrays.asList(Aggregates.match(queryNew), Aggregates.group("$similarGroup", Accumulators.sum("count", 1), Accumulators.first("data", "$$ROOT")), Aggregates.sort(Sorts.descending("data.salePrice")), Aggregates.skip(skipCount), Aggregates.limit(searchRequest.getItemsPerPage())));