我写了下面的代码:
places_ref = db_client.collection(u'places')
doc = places_ref.where (u'city_name', u'==', 'paris').get()
print(doc)
控制台输出为:
<generator object Query.get at 0x10d6736d8>
如果我尝试这个:
print(u'Document data: {}'.format(doc.to_dict()))
我收到以下错误:
AttributeError: 'generator' object has no attribute 'to_dict'
如何将查询结果转换为字典?
firestore 返回的值是一个包含许多文档的生成器。看着Firestore文档 https://pypi.org/project/google-cloud-firestore/看起来以下是你想要的,
my_dict = { el.id: el.to_dict() for el in doc }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)