Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Firestore python API捕获空QuerySnapShot? 上下文_Python_Firebase_Google Cloud Platform_Google Cloud Firestore - Fatal编程技术网

如何使用Firestore python API捕获空QuerySnapShot? 上下文

如何使用Firestore python API捕获空QuerySnapShot? 上下文,python,firebase,google-cloud-platform,google-cloud-firestore,Python,Firebase,Google Cloud Platform,Google Cloud Firestore,我想通过这种方式从Firestore获取一些数据: query=db.collection(“用户”)。其中(“年龄”,“>”,20) 对于query.stream()中的文档: 打印(“用户id:{}”。格式(document.id)) 但是,我不能断言它是否会在文档上迭代。事实上,如果没有文档与我的where条件匹配,则什么也不会发生。我想提出一个例外 问题: 我们如何用pythonapi捕捉任何空数据 资源: 如果没有与where匹配的文档,则返回null,请检查 如果查询!=无效的:

我想通过这种方式从Firestore获取一些数据:

query=db.collection(“用户”)。其中(“年龄”,“>”,20)
对于query.stream()中的文档:
打印(“用户id:{}”。格式(document.id))
但是,我不能断言它是否会在文档上迭代。事实上,如果没有文档与我的
where
条件匹配,则什么也不会发生。我想提出一个例外

问题: 我们如何用pythonapi捕捉任何空数据

资源:

如果没有与where匹配的文档,则返回null,请检查

如果查询!=无效的: 对于query
中的文档,在此处输入code
y.stream() 打印(“用户id:{}”。格式(document.id))

如果没有与where匹配的文档,则返回null,请检查

如果查询!=无效的: 对于query
中的文档,在此处输入code
y.stream() 打印(“用户id:{}.format(document.id))

我用以下方式解决:

documents = [d for d in db.collection("users").where("age", ">", 20).stream()]

if len(documents):
    for document in documents:
        print("User id: {}".format(document.id))
else:
    print('empty query') 
我这样解决:

documents = [d for d in db.collection("users").where("age", ">", 20).stream()]

if len(documents):
    for document in documents:
        print("User id: {}".format(document.id))
else:
    print('empty query') 

谢谢你的回答。然而,我不认为这是相关的。我使用的是python库,而不是js库。因此,返回值是a,而不是您建议的
null
。此外,
null
在python中不存在。感谢您的回答。然而,我不认为这是相关的。我使用的是python库,而不是js库。因此,返回值是a,而不是您建议的
null
。此外,
null
在python中不存在。我有同样的问题。你解决了吗?我最后测试了
for
循环中应该发生的操作的结果。谢谢你的回答!我有同样的问题。你解决了吗?我最后测试了
for
循环中应该发生的操作的结果。谢谢你的回答!