Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 729e37f

Browse filesBrowse files
petervandenabeelegguuss
authored andcommitted
Avoid use deprecated methods in firestore
Use `Collection.stream` instead of deprecated `Collection.get`
1 parent ee3c61f commit 729e37f
Copy full SHA for 729e37f

File tree

Expand file treeCollapse file tree

1 file changed

+13
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-13
lines changed

‎firestore/cloud-client/snippets.py

Copy file name to clipboardExpand all lines: firestore/cloud-client/snippets.py
+13-13Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def quickstart_get_collection():
5959
db = firestore.Client()
6060
# [START quickstart_get_collection]
6161
users_ref = db.collection(u'users')
62-
docs = users_ref.get()
62+
docs = users_ref.stream()
6363

6464
for doc in docs:
6565
print(u'{} => {}'.format(doc.id, doc.to_dict()))
@@ -240,7 +240,7 @@ def get_custom_class():
240240
def get_simple_query():
241241
db = firestore.Client()
242242
# [START get_simple_query]
243-
docs = db.collection(u'cities').where(u'capital', u'==', True).get()
243+
docs = db.collection(u'cities').where(u'capital', u'==', True).stream()
244244

245245
for doc in docs:
246246
print(u'{} => {}'.format(doc.id, doc.to_dict()))
@@ -254,15 +254,15 @@ def array_contains_filter():
254254

255255
query = cities_ref.where(u'regions', u'array_contains', u'west_coast')
256256
# [END fs_array_contains_filter]
257-
docs = query.get()
257+
docs = query.stream()
258258
for doc in docs:
259259
print(u'{} => {}'.format(doc.id, doc.to_dict()))
260260

261261

262262
def get_full_collection():
263263
db = firestore.Client()
264264
# [START get_full_collection]
265-
docs = db.collection(u'cities').get()
265+
docs = db.collection(u'cities').stream()
266266

267267
for doc in docs:
268268
print(u'{} => {}'.format(doc.id, doc.to_dict()))
@@ -520,7 +520,7 @@ def compound_query_invalid_multi_field():
520520
def order_simple_limit():
521521
db = firestore.Client()
522522
# [START order_simple_limit]
523-
db.collection(u'cities').order_by(u'name').limit(3).get()
523+
db.collection(u'cities').order_by(u'name').limit(3).stream()
524524
# [END order_simple_limit]
525525

526526

@@ -530,7 +530,7 @@ def order_simple_limit_desc():
530530
cities_ref = db.collection(u'cities')
531531
query = cities_ref.order_by(
532532
u'name', direction=firestore.Query.DESCENDING).limit(3)
533-
results = query.get()
533+
results = query.stream()
534534
# [END order_simple_limit_desc]
535535
print(results)
536536

@@ -550,7 +550,7 @@ def order_where_limit():
550550
cities_ref = db.collection(u'cities')
551551
query = cities_ref.where(
552552
u'population', u'>', 2500000).order_by(u'population').limit(2)
553-
results = query.get()
553+
results = query.stream()
554554
# [END order_where_limit]
555555
print(results)
556556

@@ -561,7 +561,7 @@ def order_where_valid():
561561
cities_ref = db.collection(u'cities')
562562
query = cities_ref.where(
563563
u'population', u'>', 2500000).order_by(u'population')
564-
results = query.get()
564+
results = query.stream()
565565
# [END order_where_valid]
566566
print(results)
567567

@@ -571,7 +571,7 @@ def order_where_invalid():
571571
# [START order_where_invalid]
572572
cities_ref = db.collection(u'cities')
573573
query = cities_ref.where(u'population', u'>', 2500000).order_by(u'country')
574-
results = query.get()
574+
results = query.stream()
575575
# [END order_where_invalid]
576576
print(results)
577577

@@ -609,7 +609,7 @@ def snapshot_cursors():
609609
start_at_snapshot = db.collection(
610610
u'cities').order_by(u'population').start_at(snapshot)
611611
# [END fs_start_at_snapshot_query_cursor]
612-
results = start_at_snapshot.limit(10).get()
612+
results = start_at_snapshot.limit(10).stream()
613613
for doc in results:
614614
print(u'{}'.format(doc.id))
615615

@@ -623,7 +623,7 @@ def cursor_paginate():
623623
first_query = cities_ref.order_by(u'population').limit(3)
624624

625625
# Get the last document from the results
626-
docs = first_query.get()
626+
docs = first_query.stream()
627627
last_doc = list(docs)[-1]
628628

629629
# Construct a new query starting at this document
@@ -802,7 +802,7 @@ def delete_full_collection():
802802

803803
# [START delete_full_collection]
804804
def delete_collection(coll_ref, batch_size):
805-
docs = coll_ref.limit(10).get()
805+
docs = coll_ref.limit(10).stream()
806806
deleted = 0
807807

808808
for doc in docs:
@@ -871,7 +871,7 @@ def collection_group_query(db):
871871
# [START fs_collection_group_query]
872872
museums = db.collection_group(u'landmarks')\
873873
.where(u'type', u'==', u'museum')
874-
docs = museums.get()
874+
docs = museums.stream()
875875
for doc in docs:
876876
print(u'{} => {}'.format(doc.id, doc.to_dict()))
877877
# [END fs_collection_group_query]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.