Python + Firestore:从集合中的所有文档中查询特定字段 [英] Python + Firestore : query specific fields from all documents in a collection

查看:49
本文介绍了Python + Firestore:从集合中的所有文档中查询特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从集合中的所有文档中读取特定字段,而不列出所有字段.例如,我只想从 Donut 集合中的所有文档中读取和打印 Brand .但是现在我的python脚本正在打印所有文档中的所有字段(从以下代码中获取代码:

I'm trying to read a specific field from all documents in a collection without listing all fields. For example, I want to only read and print Brand from all documents in Donut collection. But right now my python script is printing all fields in all documents (code obtained from:

推荐答案

尝试以下代码,它将打印来自Donut集合的所有文档中的所有Brand:

Try the codes below, it will print all Brand from all documents in Donut collection:

users_ref = db.collection('Donut')
docs = users_ref.stream()
for doc in docs:
    brand = u'{}'.format(doc.to_dict()['Brand'])
    print(brand)

这篇关于Python + Firestore:从集合中的所有文档中查询特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆