'How to retrieve the sorted amount using DocumentSnapshot

I store data to my firebase like this where the amt has years under it. And under the years has the months. Then under the months has amount.

uid1 > uid: uid1
     > amt:
       > 2021
         > 12
           > 500
       > 2022
         > 1
           > 100
         > 2
           > 50
uid2 > uid: uid2
     > amt:
       > 2021
         > 1
           > 250
         > 5
           > 5
uid3 > uid: uid3
     > amt:

How will I retrieve these information of uid with it's corresponding value for certain month. I wanted to use DocumentSnapshot but I don't have an idea if this is possible. Thanks!

For January 2022
uid2: 250
uid1: 100
uid3: 0

For February 2022
uid1: 50
uid2: 0
uid3: 0


Sources

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

Source: Stack Overflow

Solution Source