Firestore如何在python中从数组字段获取数据

2024-10-03 23:20:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我在如何从数组字段中获取数据/值方面遇到了问题。请看图片:

enter image description here

在图中,我想从array field (parkings)中获取parking_code的数据/值。 我试过这个:

parking2 = db.collection(u'parking').document().get({u'parkings.parking_code'})

但是它像这样返回我:<google.cloud.firestore_v1.document.DocumentSnapshot object at 0x0000014925256550>

我也尝试过这种代码:

parking2 = db.collection(u'parking').document().get({u'parkings.parking_code'}).to_dict()

但是它返回一个None值。任何对此有解决方案或至少有想法的人,请告诉我,我需要你的帮助


Tags: 数据cloudfielddbgetgoogle图片code
2条回答

根据官方文件:

A DocumentSnapshot contains data read from a document in your Cloud Firestore database. The data can be extracted with the getData() or get(String) methods.

If the DocumentSnapshot points to a non-existing document, getData() and its corresponding methods will return null. You can always explicitly check for a document's existence by calling exists().

doc_ref = db.collection(u'parking').document(u'D7k...')

doc = doc_ref.get()
print(doc.to_dict())

https://cloud.google.com/firestore/docs/query-data/get-data#custom_objects

相关问题 更多 >