【问题标题】:Firestore - How to get data from an array field in pythonFirestore - 如何从 python 中的数组字段获取数据
【发布时间】:2020-07-07 08:01:55
【问题描述】:

我在如何从作为数组的字段中获取数据/值方面遇到问题。请看图片:

在图像中,我想获取来自array field (parkings)parking_code 的数据/值。 我试过这个:

parking2 = db.collection(u'parking').document().get({u'parkings.parking_code'})

但它会像这样返回我:<google.cloud.firestore_v1.document.DocumentSnapshot object at 0x0000014925256550>

我也试过这种代码:

parking2 = db.collection(u'parking').document().get({u'parkings.parking_code'}).to_dict()

但它返回一个None 值。任何对此有解决方案或至少只是一个想法的人,我需要你的帮助。

【问题讨论】:

    标签: python python-3.x firebase google-cloud-firestore


    【解决方案1】:

    根据官方文档:

    DocumentSnapshot 包含从云中的文档读取的数据 Firestore 数据库。可以使用 getData() 或 get(String) 方法。

    如果 DocumentSnapshot 指向一个不存在的文档,getData() 其对应的方法将返回null。你总是可以 通过调用 exists() 显式检查文档是否存在。

    【讨论】:

      【解决方案2】:
      doc_ref = db.collection(u'parking').document(u'D7k...')
      
      doc = doc_ref.get()
      print(doc.to_dict())
      
      

      https://cloud.google.com/firestore/docs/query-data/get-data#custom_objects

      【讨论】:

        猜你喜欢
        • 2019-03-03
        • 1970-01-01
        • 2020-03-29
        • 1970-01-01
        • 2019-11-27
        • 2021-06-29
        • 1970-01-01
        • 2021-11-05
        相关资源
        最近更新 更多