【发布时间】:2021-01-12 12:09:30
【问题描述】:
在 python 中,我正在查看 firestore 集合的更改,并且对于每个更改,我都会收到一个包含整个集合的快照。根据documentation,这不是问题,但是,我的问题是该快照中的每个文档都有一个“添加”的更改类型,那么我应该如何确定刚刚添加的是哪个文档?
#callback Function
def on_snapshot(doc_snapshot, changes, read_time):
print('on_snapshot..')
for change in changes:
if change.type.name == 'ADDED':
#this is the new document..
#which of the documents in the snapshot are of change.type.name = 'ADDED'?
else:
#some modified/deleted document..
【问题讨论】:
-
触发事件的文档将在添加案例中的快照侦听器中。
-
@s_o_m_m_y_e_e 在我的情况下,我正在获取 ADDED 案例中的所有文件。
-
基本上,您的快照侦听器会为您提供您请求的数据,除此之外,它还会立即为您提供其中的任何更改。所以你添加的情况意味着一些数据已经添加到你正在接收的数据库中。
标签: python firebase firebase-realtime-database google-cloud-firestore