Reputation: 103
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
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:
snapshot.getChildrenCount()
.snapshot.childrenCount
property.snapshot.size
propertyIf 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
Reputation: 11156
Supposing that you have geoTag
object locally to your application, you could just call:
Object.keys(geoTag).length
Upvotes: 0