'Aggregating firestore collectionGroups (e.g. find root document maximum)

I use Firestore JavaScript v9. I have a data structure of items with deeply nested tasks, like this:

  • item A
    • task1
      • task1.1
    • task2
  • item B
    • task1
    • task2
      • task2.1
        • task2.1.1

Every Task has an endDate Timestamp and a subcollection "subTasks".

How can I query the max / latest endDate of all subTasks within an item?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source