Firestore-Sammlungsgruppe mit einem eq-Filter abfragen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Firestore-Sammlungsgruppe mit einem eq-Filter abfragen
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[],[],null,["# Query a Firestore collection group with an eq filter\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Perform simple and compound queries in Cloud Firestore](https://firebase.google.com/docs/firestore/query-data/queries)\n- [Query and filter data](/firestore/native/docs/query-data/queries)\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 Query museums = db.CollectionGroup(\"landmarks\").WhereEqualTo(\"Type\", \"museum\");\n QuerySnapshot querySnapshot = await museums.GetSnapshotAsync();\n foreach (DocumentSnapshot document in querySnapshot.Documents)\n {\n Console.WriteLine($\"{document.Reference.Path}: {document.GetValue\u003cstring\u003e(\"Name\")}\");\n }\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 import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \t\"cloud.google.com/go/firestore\"\n \t\"google.golang.org/api/iterator\"\n )\n\n // collectionGroupQuery runs a collection group query over the data created by\n // collectionGroupSetup.\n func collectionGroupQuery(w io.Writer, projectID string) error {\n \tctx := context.Background()\n\n \tclient, err := firestore.NewClient(ctx, projectID)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"firestore.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \tit := client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/index.html#cloud_google_com_go_firestore_Client_CollectionGroup(\"landmarks\").https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/index.html#cloud_google_com_go_firestore_Query_Where(\"type\", \"==\", \"museum\").Documents(ctx)\n \tfor {\n \t\tdoc, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn fmt.Errorf(\"documents iterator: %w\", err)\n \t\t}\n \t\tfmt.Fprintf(w, \"%s: %s\", doc.Ref.ID, doc.https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/index.html#cloud_google_com_go_firestore_DocumentSnapshot_Data()[\"name\"])\n \t}\n\n \treturn nil\n }\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 final Query museums = db.collectionGroup(\"landmarks\").whereEqualTo(\"type\", \"museum\");\n final ApiFuture\u003cQuerySnapshot\u003e querySnapshot = museums.get();\n for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {\n System.out.println(document.getId());\n }\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 querySnapshot = await db.collectionGroup('landmarks').where('type', '==', 'museum').get();\n querySnapshot.forEach((doc) =\u003e {\n console.log(doc.id, ' =\u003e ', doc.data());\n });\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 $museums = $db-\u003ecollectionGroup('landmarks')-\u003ewhere('type', '==', 'museum');\n foreach ($museums-\u003edocuments() as $document) {\n printf('%s =\u003e %s' . PHP_EOL, $document-\u003eid(), $document-\u003edata()['name']);\n }\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 museums = db.collection_group(\"landmarks\").where(\n filter=FieldFilter(\"type\", \"==\", \"museum\")\n )\n docs = museums.stream()\n for doc in docs:\n print(f\"{doc.id} =\u003e {doc.to_dict()}\")\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 museums = firestore.collection_group(\"landmarks\").where(\"type\", \"==\", \"museum\")\n museums.get do |museum|\n puts \"#{museum[:type]} name is #{museum[:name]}.\"\n end\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)."]]