简体   繁体   English

如何使用带有 get() 的 firebase_admin 查询 firestore 文档

[英]How do I query a firestore document using firebase_admin with get()

I am trying to retrieve a document from firestore using python but I keep seeing a context error.我正在尝试使用 python 从 firestore 检索文档,但我一直看到上下文错误。 Upon some research I found that the firebase_admin sdk is using async calls and python is not waiting, but with that knowledge I am still unable to successfully call the.get() method on a collection reference.经过一些研究,我发现 firebase_admin sdk 正在使用异步调用,而 python 没有等待,但据此我仍然无法在集合引用上成功调用 .get() 方法。 Here is an example:这是一个例子:

firebase_admin.initialize_app(cred)
db = firestore.client()
subscription_data = db.collection("subscriptions").document(purchaseToken)
doc = subscription_data.get()

This is the error on the server:这是服务器上的错误:

RuntimeError: cannot exit context: thread state references a different context object

I did attempt to use asyncio with no luck.我确实尝试过使用 asyncio,但没有成功。

From the documentation on getting a document I see this snippet for doing so in async Python code:从有关获取文档的文档中,我在异步 Python 代码中看到了这样做的片段:

doc_ref = db.collection("cities").document("SF")

doc = await doc_ref.get()
if doc.exists:
    print(f"Document data: {doc.to_dict()}")
else:
    print("No such document!")

So it seems like await might be your way out here.所以看起来await可能是你的出路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 firebase_admin 上使用“where”查询时无法过滤数据 - cannot filter data when using `where` query on firebase_admin Firestore AttributeError:模块“firebase_admin”没有属性“firestore” - Firestore AttributeError: module 'firebase_admin' has no attribute 'firestore' 如何在 python 上调试 firebase_admin - How to debug firebase_admin on python 如何使用 firebase_admin 从 python 中的 firebase 存储中下载文件 - How to download file from firebase storage in python using firebase_admin 如何使用查询从 Firebase 9 js 中删除文档? - How do I delete a document from Firebase 9 js using a query? 如何使用 NextJs API、Firebase Firestore、axios 和 TypeScript 从 Firebase 集合中获取数据? - How do I get data from Firebase collection using NextJs API, Firebase Firestore, axios and TypeScript? 如何获取插入文档的 ID firebase-admin - How can I get the id of a inserted document firebase-admin 如何获取 firebase Firestore 文档 ID - How to get the firebase firestore document id 如何从 Firebase Firestore 集合中指定文档的特定字段获取数据并将其显示到我的 UI? - How do I get data from a specific field of the specified document inside a Firebase Firestore collection and display it to my UI? 如何从 Firestore 获取文档 ID 列表 - How do I get a list of document ID’s from Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM