Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore DocumentSnapshot to Python dictionary

Hi I've been going around in circles trying to get my Firestore data into a Python 2 dictionary.

    doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2')
    doc = doc_ref.get()

gets me a DocumentSnapshot - I was hoping to get a dict. What's the proper way to create a dict from the results. Tried the docs and just end up with the object. Something dumb I'm (not) doing.

Thanks

like image 783
Townheadbluesboy Avatar asked Jul 11 '26 04:07

Townheadbluesboy


1 Answers

You could use to_dict(), this should give you the dictionary of the result.

doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2') 
doc = doc_ref.get().to_dict()
like image 113
ellaRT Avatar answered Jul 13 '26 18:07

ellaRT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!