Hi,
I have 1 parent document and 2 nested documents
Document
public class F {
private String id;
DBRef
private S s;
DBRef
private P p;
private String status;
}
Document
public class S {
private String id;
}
Document
public class P {
private String id;
private long r;
}
now I have in hand subdocument S id and document F status .I want to fetch 5 F documents, based on subdocument S id (“123334”) , Document F status (“COMPLETE”) and the result should be sorted by subdocument P, r property ?
I have tried the below spring-data, but the sorting never worked
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("status").is("COMPLETE")),
Aggregation.unwind("s"),
Aggregation.match(Criteria.where("s.$id").is(new ObjectId("123334"))),
Aggregation.unwind("p"),
Aggregation.sort(new Sort(Sort.Direction.DESC, "p.r")),
Aggregation.limit(5));
List<F> fs = mongoOperation.aggregate(aggregation, "f", F.class).getMappedResults();