Skip to content

Commit 8a43dec

Browse files
Mariattadandhlee
andauthored
Firestore use dict (GoogleCloudPlatform#8353)
* Firestore client: Update snippet and use a dictionary Instead of a previously undeclared custom City class. Fixes internal issue: 244038329 * Show how to use the autogenerated id * Revert change in project id Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com>
1 parent 0c6bb0f commit 8a43dec

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

firestore/cloud-client/snippets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ def add_data_with_id():
211211
def add_custom_class_generated_id():
212212
db = firestore.Client()
213213
# [START firestore_data_set_id_random_collection]
214-
city = City(name=u'Tokyo', state=None, country=u'Japan')
215-
db.collection(u'cities').add(city.to_dict())
214+
city = {
215+
u'name': u'Tokyo',
216+
u'country': u'Japan'
217+
}
218+
update_time, city_ref = db.collection(u'cities').add(city)
219+
print(f'Added document with id {city_ref.id}')
216220
# [END firestore_data_set_id_random_collection]
217221

218222

0 commit comments

Comments
 (0)