Roy Sougat
Roy Sougat

Reputation: 103

how to count number of keys in firebase real time database

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

Upvotes: 6

Views: 4621

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 599571

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.

Upvotes: 10

Giovanni Esposito
Giovanni Esposito

Reputation: 11156

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

Object.keys(geoTag).length

Upvotes: 0

Related Questions