基于Firestore更改触发云功能

2024-04-18 16:53:04 发布

您现在位置:Python中文网/ 问答频道 /正文

每当某个俱乐部的文档被更改(创建、修改、删除)时,我都想触发我的云函数。我的云功能应该捕获哪些数据被修改并进一步发布到pub/sub

所有这些都是用python实现的。你知道吗

我试着这样:

query = db.collection('cities') query_watch = col_query.on_snapshot(callback)

城市-Firestore系列。你知道吗

这是我的回调函数-

def callback(col_snapshot, changes, read_time):
print('callback.')

此查询属于watch object类型。我怎样才能从中提取细节,比如什么是三角洲。?你知道吗

遵循此文档-https://firebase.google.com/docs/firestore/query-data/listen


Tags: 数据函数文档功能dboncallbacksnapshot
1条回答
网友
1楼 · 发布于 2024-04-18 16:53:04

根据文件:

# Create a callback on_snapshot function to capture changes
def on_snapshot(doc_snapshot, changes, read_time):
    for doc in doc_snapshot:
        # Here you retrieve the data
        print(u'Received document snapshot: {}'.format(doc.id))

doc_ref = db.collection(u'cities').document(u'SF')

# Watch the document
doc_watch = doc_ref.on_snapshot(on_snapshot)

def callback(col_snapshot, changes, read_time)中,您需要根据需要处理接收到的数据。你知道吗

print()将运行两次,因为:

An initial call using the callback you provide creates a document snapshot immediately with the current contents of the single document. Then, each time the contents change, another call updates the document snapshot.

相关问题 更多 >