【发布时间】:2018-12-31 04:01:41
【问题描述】:
我正在使用来自 google.cloud 的 firestore 库, 有没有办法在不检索所有数据的情况下检查文档是否存在? 我试过了
fs.document("path/to/document").get().exists()
但它返回 404 错误。 (google.api_core.exceptions.NotFound)
然后我尝试了
fs.document("path/to/document").exists()
但“存在”不是 DocumentReference 中的函数。
从源码中可以看出,exists() 是 DocumentSnapshot 类中的一个函数,而 get() 函数应该返回一个 documentSnapshot。我不太确定我还能如何获得 DocumentSnapshot
谢谢
【问题讨论】:
-
我在 firebase admin v 2.14.0 上遇到了同样的问题,当文档不存在时,
db.collection('...').document('...').get()会抛出google.api_core.exceptions.NotFound: 404。很奇怪,这似乎是我服务器上最近出现的问题,并且在我的 macbook 安装上运行良好(....get().exists无一例外地返回 False)
标签: python-3.x google-cloud-firestore