Skip to content

Adjust Cloud Firestore update_doc_array snippet to not require an extra import #2306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions firestore/cloud-client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from time import sleep

from google.cloud import firestore
from google.cloud.firestore_v1 import ArrayRemove, ArrayUnion
import google.cloud.exceptions


Expand Down Expand Up @@ -319,10 +318,10 @@ def update_doc_array():
city_ref = db.collection(u'cities').document(u'DC')

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

# // Atomically remove a region from the 'regions' array field.
city_ref.update({u'regions': ArrayRemove([u'east_coast'])})
city_ref.update({u'regions': firestore.ArrayRemove([u'east_coast'])})
# [END fs_update_doc_array]
city = city_ref.get()
print(u'Updated the regions field of the DC. {}'.format(city.to_dict()))
Expand Down