Skip to main content
 首页 » 编程设计

python之只听 python 中云 firestore 集合的添加

2024年08月13日44kenshinobiy

只有在将新文档添加到 Firebase 中的特定集合时,代码才会触发。

我已经找到一个 answer对于 javascript 中的这个问题,但我无法找出 python 的解决方案。

请您参考如下方法:

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)