diff --git a/firestore/cloud-client/snippets.py b/firestore/cloud-client/snippets.py index 67545df4ac9..bd55e9bac59 100644 --- a/firestore/cloud-client/snippets.py +++ b/firestore/cloud-client/snippets.py @@ -557,6 +557,22 @@ def cursor_simple_end_at(): return query_end_at +def snapshot_cursors(): + db = firestore.Client() + # [START fs_start_at_snapshot_query_cursor] + doc_ref = db.collection(u'cities').document(u'SF') + + snapshot = doc_ref.get() + start_at_snapshot = db.collection( + u'cities').order_by(u'population').start_at(snapshot) + # [END fs_start_at_snapshot_query_cursor] + results = start_at_snapshot.limit(10).get() + for doc in results: + print('{}'.format(doc.id)) + + return results + + def cursor_paginate(): db = firestore.Client() # [START cursor_paginate] diff --git a/firestore/cloud-client/snippets_test.py b/firestore/cloud-client/snippets_test.py index f3e6bdaf4b7..98bf4be7357 100644 --- a/firestore/cloud-client/snippets_test.py +++ b/firestore/cloud-client/snippets_test.py @@ -195,6 +195,14 @@ def test_cursor_simple_end_at(): snippets.cursor_simple_end_at() +def test_snapshot_cursors(capsys): + snippets.snapshot_cursors() + out, _ = capsys.readouterr() + assert "SF" in out + assert "TOK" in out + assert "BJ" in out + + def test_cursor_paginate(): snippets.cursor_paginate()