【问题标题】:Firestore cannot get path onsnapshotFirestore 无法获取路径快照
【发布时间】:2019-10-17 23:30:41
【问题描述】:

我正在收听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

【问题讨论】:

标签: python firebase google-cloud-firestore


【解决方案1】:

DocumentSnapshot 的 API 文档说可以在其 reference 属性中找到该文档的引用。所以你会想要使用这个:doc.reference

【讨论】:

  • 谢谢,我一定是看错文档了
  • 我认为你应该发布一个新问题,解释现在什么不符合你的预期。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-26
  • 2020-12-16
  • 2023-03-19
  • 2023-04-10
  • 1970-01-01
  • 2013-01-20
  • 1970-01-01
相关资源
最近更新 更多