Firestore无法获取路径快照

时间:2019-06-01 19:46:57

标签: python firebase google-cloud-firestore

我正在监听collection_group的数据库更改 我无法访问DocumentSnapshot的ref(具有路径),但不断收到错误消息:

AttributeError: 'DocumentSnapshot' object has no attribute 'ref'

这是我的代码:

doc_ref = firestore_db.collection_group(u'collection_name')
doc_ref.on_snapshot(self.__get_snapshot(args))

这是我的__get_snapshot方法:

def __get_snapshot(self, args):
    def on_snapshot(doc_snapshot, changes, read_time):
        for doc in doc_snapshot: #crashes
            print(u'Received document snapshot: {}'.format(doc.ref))
        for change in changes:
            if(change.type.name == "MODIFIED"):
                print(change.document.ref) #crashes
                print(change.document.get("field"))#this works fine
return on_snapshot

1 个答案:

答案 0 :(得分:1)

DocumentSnapshot的API文档说,该文档的引用可以在其reference属性中找到。因此,您将要使用:doc.reference

相关问题