4

enter image description here

How do I count number of keys, with the help of firebase functions, in above case there are 3. I am using firebase real time database

Shreyas Sanil
  • 532
  • 1
  • 7
  • 19
Roy Sougat
  • 83
  • 7

2 Answers2

10

There is no separate count operation for Firebase Realtime Database. You'll have to download the entire snapshot of the parent node (geoTag) and then count the number of children in your application code.

How to do this, depends on the platform:

If you have many children and all you need is the count, the above quickly becomes overly wasteful. In such cases, it's best to store the child count in a separate property yourself, and update it whenever you add/remove child nodes. Then you can read only the counter when you need that. There is even a sample Cloud Function that does this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

Supposing that you have geoTag object locally to your application, you could just call:

Object.keys(geoTag).length
Giovanni Esposito
  • 10,696
  • 1
  • 14
  • 30