Firestore DocumentSnapshot至Python字典

Tow*_*boy 0 python google-cloud-firestore

嗨,我一直在兜圈子,试图将我的Firestore数据放入Python 2字典中。

    doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2')
    doc = doc_ref.get()
Run Code Online (Sandbox Code Playgroud)

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

谢谢

was*_*898 5

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

doc_ref = db.collection('things1').document('ref1').collection('things2').document('ref2') 
doc = doc_ref.get().to_dict()
Run Code Online (Sandbox Code Playgroud)

  • 为什么这突然不是正确答案?@Townheadbluesboy? (2认同)