Firestore DocumentSnapshot到Python字典

时间:2018-03-02 21:06:48

标签: python google-cloud-firestore

您好我一直在试图将我的Firestore数据导入Python 2词典。

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

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

由于

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:0)

这对我有用。

df <- df[order(match(df$Condition, paste0(rep(LETTERS[1:3],each = 2), rep(1:2, 3)))), ]