【发布时间】:2020-02-02 20:26:03
【问题描述】:
我正在尝试使用 python 读取 Google Cloud Firestore 中的特定数据字段。
我的 Firestore 数据库中有一个名为 Products 的集合,并且手动添加了多个具有不同字段的文档。
到目前为止,我可以使用以下方法提取文档:
docs = db.collection(u'Products').where(u'checked', u'==', False).stream()
for doc in docs:
print(u'{} => {}'.format(doc.id, doc.to_dict()))
这可行,我收到以下输出:
Test2 => {'link': 'https://stackoverflow.com', 'price': 14, 'checked': False}
但是,我无法从该字典中提取单独的“链接”字符串。我试过了:
print(doc.to_dict('link'))
并多次迭代,得到以下输出:
to_dict() 接受 1 个位置参数,但给出了 2 个
我一直在关注 firebase 文档 here,但没有找到专门打印字段的示例。
关于如何从我使用的查询中打印“链接”字符串的任何建议?
我正在运行 Python 3.7。
提前感谢您的帮助。
【问题讨论】:
标签: python firebase dictionary google-cloud-firestore