Search code examples
pythonfirebasefirebase-admin

'firebase_admin.db' has no attribute 'child'


While I was trying to practice on python and firebase I got this error.

 'firebase_admin.db' has no attribute 'child'

here is my imports

from firebase_admin import db

and the code that gives error.

dates = db.child("notes").get()

I have no idea why this error pops up. when I read firebase_admin documents it shows there is a child() method. What am I missing here?

Thanks for the help.


Solution

  • Your db is a firebase_admin.db object, which (as the error says) doesn't have a child() method. To get a reference from the top-level, you'll use the reference method:

    dates = db.reference("notes").get()
    

    To get references to lower-level nodes, you can use child on the result of reference, so for example:

    db.reference("notes").child("nameofchildnode")
    

    Also see the Firebase documentation on getting started with the Python Admin SDK.