是否可以检查馆藏中是否有文件?

时间:2019-11-15 17:29:30

标签: python firebase google-cloud-firestore

有没有一种方法可以检查python集合中是否至少有1个或多个文档?

我已经尝试过了,如果有文档,它就可以工作,但是如果没有任何文档,则循环根本不会运行,这很有意义,因为没有文档可以循环通过。

currentGame = db.collection(u'currentGame').stream()
try:
    for doc in currentGame:
        if doc.exists:
            print("exists")
        else:
            print("no document")

except google.cloud.exceptions.NotFound:
    print("not found")

0 个答案:

没有答案
相关问题