![](/img/trans.png)
[英]How to query documents from a sub-collection, based on a main collection's field and a sub-collection's fields in cloud firestore?
[英]How to Query for documents in a sub collection in Firestore?
我知道如何从根集合中查询子集合中的文档有一些限制,但是当您引用子集合时,它应该不是问题,应该吗(???)
结构如下所示:
SensorName(集合)-> MyDocument(文档)-> SensorHistory(子集合)
doc_ref = db.collection('sensorData').document('Engineroom').collection('History').order_by("timestamp").where(u"SensorType", u"==", 'temp')
result = doc_ref.stream().to_dict()
print(result)
这是我得到的错误
结果 = doc_ref.stream().to_dict() AttributeError: 'generator' object has no attribute 'to_dict'
我真的需要将我的历史集合放在根目录中才能查询吗?
还是我在我的代码中犯了错误? :)
谢谢你的帮助:)
stream()
方法返回文档快照的生成器。 在调用to_dict
之前,您需要从生成器中获取文档快照:
result = doc_ref.stream()
for doc in result:
print(doc.to_dict())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.