firebase_admin firestore的实时事件侦听是否可行



我正在为我的flask应用程序使用python firebase admin-sdk。是否可以监听集合上的实时事件(如添加的文档(?

一些文档表明这是可能的,但其他文档和我自己的测试表明了其他方面的可能性。

详细信息

CollectionReference的文档指出,on_snapshot可用于在集合上注册事件侦听器。

然而,这个消防商店教程说"Note: Realtime listeners are not supported in Python and PHP."。所以有两个相互矛盾的来源此外,在我自己的测试中,我发现on_snapshot不是CollectionReference的属性,这表明该功能是不可能的。

你能确认在python firestore admin sdk中实时监听是否可能吗?

相关代码:

on_snapshot的文档说这个代码应该能在中工作

from google.cloud import firestore
db = firestore.Client()
collection_ref = db.collection(u'users')
def on_snapshot(collection_snapshot):
for doc in collection_snapshot.documents:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
collection_watch = collection_ref.on_snapshot(on_snapshot)

但是它给了我一个错误AttributeError: 'CollectionReference' object has no attribute 'on_snapshot'

这还没有发布。上一次发布时间为2018年10月,on_snapshot方法已添加到11月的PR中:https://github.com/googleapis/google-cloud-python/pull/6191

我认为API引用是从GitHub主分支自动生成的,这就是它出现在那里的原因。

最新更新