Reputation: 199
I have written the following piece of code:
places_ref = db_client.collection(u'places')
doc = places_ref.where (u'city_name', u'==', 'paris').get()
print(doc)
The console output is:
<generator object Query.get at 0x10d6736d8>
If I try this:
print(u'Document data: {}'.format(doc.to_dict()))
I get the following error:
AttributeError: 'generator' object has no attribute 'to_dict'
How do I convert the query result to a dictionary?
Upvotes: 4
Views: 6033
Reputation: 2507
The returned value from firestore is a generator containing many documents. Looking at the firestore docs it looks like the following is what you want,
my_dict = { el.id: el.to_dict() for el in doc }
Upvotes: 8