eq フィルタを使用して Firestore コレクション グループに対してクエリを実行する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
eq フィルタを使用して 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"]],[],[],[],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)."]]