仅收听python中的Cloud Firestore集合的附加内容

时间:2019-04-17 12:21:02

标签: python firebase google-cloud-firestore

仅当将新文档添加到Firebase中的特定集合中时,代码才应触发。

我已经在javascript中找到了answer来解决此问题,但是我找不到python的解决方案。

1 个答案:

答案 0 :(得分:0)

documentation包含如何执行此操作的示例(请查看“ python”标签):

def on_snapshot(col_snapshot, changes, read_time):
    print(u'Callback received query snapshot.')
    print(u'Current cities in California: ')
    for change in changes:
        if change.type.name == 'ADDED':
            print(u'New city: {}'.format(change.document.id))
        # Removed other cases

col_query = db.collection(u'cities').where(u'state', u'==', u'CA')

# Watch the collection query
query_watch = col_query.on_snapshot(on_snapshot)