0

I need to count all children in third level in a Firebase database.

here is my database structure :

Level 1
 - CHILD1
   - - subchild11
   - - subchild12
- CHILD2
   - - subchild21

I need to get the count (in this case it's 3) of elements in third level ( subchild11 , subchild12 , subchild21)

leonidas79
  • 437
  • 2
  • 7
  • 19
  • There is no simple query to get a count. You're going to have to read everything under "Level 1", and write code on the client to find and count all of the subchildren nodes. – Doug Stevenson Oct 07 '20 at 15:22
  • I added a few links, but in this case you'll need to count child nodes one level deeper as Doug says. This is both finicky in code and wasteful in bandwidth, so the recommendation for non-trivial cases is to keep a `childCount` node in your database, and update that with every add/remove operation. – Frank van Puffelen Oct 07 '20 at 16:33

0 Answers0