3

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?

sheikhisham
  • 83
  • 1
  • 2
  • 8

1 Answers1

0

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.

eyoeldefare
  • 2,136
  • 1
  • 15
  • 25