0

i am doing some testing with firestore. I am wondering how i can get the values from each individual variable in a document in firebase and store it in separate variables.

i have followed some tutorials but all they have shown is how to see the whole document:

result = db.collection('Doinkulator').document("DoinkulatorData").get()
print(result.to_dict())

with this at the output

{'HvorMyeForEtt': 0, 'kjopt': 1, 'HvorMye': 3, 'HvemHarMed': 'knut'}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Whenever you read a document, you always get the whole document in the returned snapshot. You have to write code to extract the fields from the document snapshot into variables, if that's what you want. – Doug Stevenson Jun 13 '22 at 23:41

1 Answers1

0

To get value from a specific field in the document, you can do:

hvor = doc.to_dict()["HvorMyeForEtt"]

You can also unpack multiple fields in one go, as shown in Elegant way to unpack limited dict values into local variables in Python and Destructuring-bind dictionary contents

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807