Firestore DocumentSnapshot到Python字典

问题描述 投票:0回答:1

嗨,我一直在试图将我的Firestore数据转换为Python 2字典。

    doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2')
    doc = doc_ref.get()

给我一个DocumentSnapshot - 我希望得到一个字典。从结果中创建字典的正确方法是什么。尝试了文档,最后得到了对象。我(不)做的事情是愚蠢的。

谢谢

python google-cloud-firestore
1个回答
2
投票

你可以使用to_dict()。这应该给你结果的字典。

doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2') 
doc = doc_ref.get().to_dict()
© www.soinside.com 2019 - 2024. All rights reserved.