Python 无法导入FieldValue.arrayUnion

Python 无法导入FieldValue.arrayUnion,python,google-cloud-firestore,Python,Google Cloud Firestore,我想在Firebase Cloud Firestore中的数组中追加数据。为此,我使用了FieldValue.arrayUnion 我厌倦了这些进口货,但都不管用 from firebase_admin import firestore firebase_admin.firestore.FieldValue.arrayUnion() AttributeError: module 'firebase_admin.firestore' has no attribute 'FieldValue'

我想在Firebase Cloud Firestore中的数组中追加数据。为此,我使用了
FieldValue.arrayUnion

我厌倦了这些进口货,但都不管用

from firebase_admin import firestore
firebase_admin.firestore.FieldValue.arrayUnion()

AttributeError: module 'firebase_admin.firestore' has no attribute 'FieldValue'

想知道从何处导入FieldValue

您可以从Firestore导入ArrayRemove和ArrayUnion:

from google.cloud.firestore import ArrayUnion, ArrayRemove
或者像这样使用它们:

city_ref = db.collection(u'cities').document(u'DC')

# Atomically add a new region to the 'regions' array field.
city_ref.update({u'regions': firestore.ArrayUnion([u'greater_virginia'])})

# // Atomically remove a region from the 'regions' array field.
city_ref.update({u'regions': firestore.ArrayRemove([u'east_coast'])})
from google.cloud.firestore import ArrayUnion, ArrayRemove
city_ref = db.collection(u'cities').document(u'DC')

# Atomically add a new region to the 'regions' array field.
city_ref.update({u'regions': firestore.ArrayUnion([u'greater_virginia'])})

# // Atomically remove a region from the 'regions' array field.
city_ref.update({u'regions': firestore.ArrayRemove([u'east_coast'])})