0

I have a single document, This single document is output of an aggregation pipeline as:

match -> lookup

Document I get has an array field. Array contains multiple objects, each having a date field. I need to sort this array in descending order of date.

I can do it in java code by making a list from array and then using comparator to sort the list, and then replacing array in document with sorted list.

Can it be done in aggregation pipeline?

Mandroid
  • 6,200
  • 12
  • 64
  • 134
  • See also [mongodb group values by multiple fields](https://stackoverflow.com/a/22935461/2313887) for a different and more efficient usage example. Also noting that there is a current running MongoDB University course which actually also presents you with this exact same problem. – Neil Lunn Mar 24 '19 at 12:14
  • I actually want this solution to solve a problem in that course.:) – Mandroid Mar 24 '19 at 12:16
  • Which is actually why you should not be posting here. The point of the course is for you to "learn things". Not simply pass because you got all the answers from Stack Overflow. That was basically my gentle way of saying "We know the course is running, and we are watching". Work out the solutions instead of asking others to answer them for you here. – Neil Lunn Mar 24 '19 at 12:21

0 Answers0