Consultar uma coleção do Firestore com um filtro cursor start at document
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Consultar uma coleção do Firestore com um filtro cursor start at document
Mais informações
Para ver a documentação detalhada que inclui este exemplo de código, consulte:
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","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)."]]