【发布时间】:2021-04-22 11:15:35
【问题描述】:
我试图在我的 Firebase 集合中获取查询返回的记录数,但我无法检索查询返回的记录数。
from google.cloud import firestore as cloud_firestore
firestore = cloud_firestore.Client()
posts_ref = firestore.collection('posts')
docs = posts_ref.where('slug', '==', post['slug']).stream() # The is an iterable which can be looped over
# This throws an error; TypeError: object of type 'generator' has no len()
if len(docs) != 0:
print("Post already exists!")
exit()
# add_post_to_db()...
请有人帮助我如何获取从此查询返回的记录数。我很难处理这个。
【问题讨论】:
-
docs.len, docs.size, docs.size(), ...?
标签: python firebase google-cloud-firestore