cursor start at document フィルタを使用して Firestore コレクションに対してクエリを実行する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
cursor start at document フィルタを使用して Firestore コレクションに対してクエリを実行する
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
C#
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Go
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
PHP
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Ruby
Firestore に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page demonstrates how to query a Firestore collection using a cursor that starts at a specific document, effectively using a document snapshot as a starting point for the query.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples provided illustrate this technique across various programming languages, including C#, Go, Java, Node.js, PHP, Python, and Ruby, showcasing language specific syntax.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample requires Firestore authentication via Application Default Credentials, as explained in the linked documentation on setting up a local development environment.\u003c/p\u003e\n"],["\u003cp\u003eThe examples all use a \u003ccode\u003ecities\u003c/code\u003e collection, with the 'SF' document, and sorting by 'population' field to demonstrate the use of \u003ccode\u003eStartAt\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe page references related documentation for further information on pagination and query cursors within Firestore.\u003c/p\u003e\n"]]],[],null,["# Query a Firestore collection with a cursor start at document filter\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Paginate data with query cursors](/firestore/native/docs/query-data/query-cursors)\n- [Paginate data with query cursors](https://firebase.google.com/docs/firestore/query-data/query-cursors)\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n CollectionReference citiesRef = db.Collection(\"cities\");\n DocumentReference docRef = citiesRef.Document(\"SF\");\n DocumentSnapshot snapshot = await docRef.GetSnapshotAsync();\n Query query = citiesRef.OrderBy(\"Population\").StartAt(snapshot);\n\n### Go\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n cities := client.Collection(\"cities\")\n dsnap, err := cities.Doc(\"SF\").Get(ctx)\n if err != nil {\n \tfmt.Println(err)\n }\n query := cities.OrderBy(\"population\", firestore.Asc).StartAt(dsnap.Data()[\"population\"]).Documents(ctx)\n\n### Java\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Fetch the snapshot with an API call, waiting for a maximum of 30 seconds for a result.\n ApiFuture\u003cDocumentSnapshot\u003e future = db.collection(\"cities\").document(\"SF\").get();\n DocumentSnapshot snapshot = future.get(30, TimeUnit.SECONDS);\n\n // Construct the query\n Query query = db.collection(\"cities\").orderBy(\"population\").startAt(snapshot);\n\n### Node.js\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const docRef = db.collection('cities').doc('SF');\n const snapshot = await docRef.get();\n const startAtSnapshot = db.collection('cities')\n .orderBy('population')\n .startAt(snapshot);\n\n await startAtSnapshot.limit(10).get();\n\n### PHP\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n $citiesRef = $db-\u003ecollection('samples/php/cities');\n $docRef = $citiesRef-\u003edocument('SF');\n $snapshot = $docRef-\u003esnapshot();\n\n $query = $citiesRef\n -\u003eorderBy('population')\n -\u003estartAt($snapshot);\n\n### Python\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n doc_ref = db.collection(\"cities\").document(\"SF\")\n\n snapshot = doc_ref.get()\n start_at_snapshot = (\n db.collection(\"cities\").order_by(\"population\").start_at(snapshot)\n )\n\n### Ruby\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n doc_ref = firestore.doc \"#{collection_path}/SF\"\n snapshot = doc_ref.get\n query = cities_ref.order(\"population\").start_at(snapshot)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=firestore)."]]