I know this question may sound silly, but how can I properly query data using the Firebase Admin SDK (Cloud Firestore) with Python?
Yes, I have read the docs here:
My database:

My code:
existing_post = db.collection(u'posts').where(u'id', u'==', u'BpzIbkqAkk0').get()
print(existing_post)
I also tried omitting the .get() method, but also getting the same result each time.
All I've been getting is
<google.cloud.firestore_v1beta1.query.Query object at 0x10e7aab00>
Any ideas?
@Gerardo's comment has lead me to the right direction. Here's the working code:
existing_posts = db.collection(u'posts').where(u'id', u'==', u'BpzIbkqAkk0').get()
for post in existing_posts:
print(u'{} => {}'.format(post.id, post.to_dict()))
You have to convert generator object into dictionary format using to_dict().
Then you can easily access whatever value you want.
existing_posts = db.collection(u'posts').document(u'id').get()
result=existing_posts.to_dict()
id='BpzIbkqAkk0'
result_id=result[id]
try this it may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With