当我使用Firestore查询数据时,此方法有效:
doc_ref = db.document(u'myPath')
doc = doc_ref.get()
print doc.to_dict()['a']['b']['c']
如果我有x = ['a', 'b', 'c']
,如何使用doc.to_dict()
命令传递它以获得与上面相同的结果?还是应该修改x
?
答案 0 :(得分:1)
我终于通过使用以下方法使其工作。
doc_ref = db.document(u'myPath')
doc = doc_ref.get()
x = ['a', 'b', 'c']
print reduce(lambda val, key: val.get(key) if val else None, x, doc.to_dict())