0

How can we do count() for firebase database in python ?

as for example ..

count = db.child("users").get().count()

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Realtime Database doesn't have a simple count operation. You have to download the entire contents of the node and count the children on the client, or maintain a count value somewhere else in your database when the data changes. – Doug Stevenson Dec 14 '19 at 16:50

1 Answers1

1

You can use the len function for this as:

len(db.child('users').get().val())

Reznik
  • 2,663
  • 1
  • 11
  • 31
  • @YusufMohdSuhair if you think its the right answer mark it as currect and upvote please :) – Reznik Dec 14 '19 at 11:45
  • 2
    This is **not** a count operation. This is downloading the entire contents of the database at the "users" location, then counting the number of children on the client. If you do this, it could cost a lot of time and money. Be aware of that before you use this code. – Doug Stevenson Dec 14 '19 at 16:49
  • 1
    hmmm do you have any idea for the best way for counting it ? – Yusuf Mohd Suhair Dec 15 '19 at 12:26