spring mongodb - sort nested collection field

Viewed 586

I have nested collection inside a java spring mongodb object. Can I sort the nested collection based on the values it hold?

class A {
List<B> blist;
..
}

class B {
String date;
}

So here, I want to sort the blist collection based on the date. Is it possible by spring annotations?

1 Answers

No, you can't.

Sort can only be used on iterable objects in which the document A is not since its a single document holding Iterable nested objects. You can't sort a single object. You will have to sort the list manually after you get the collections from document A programmatically.

Related