簡體   English   中英

如何在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM