Firestore を使用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Firestore スタートガイド
コードサンプル
Node.js
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 guide provides code samples in Kotlin and Node.js for interacting with Firestore.\u003c/p\u003e\n"],["\u003cp\u003eThe Kotlin code demonstrates how to create a Firestore client, fetch a document reference, retrieve data, and handle potential errors.\u003c/p\u003e\n"],["\u003cp\u003eThe Node.js code illustrates how to create a Firestore client, set, update, read, and delete a document.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Firestore can be set up through Application Default Credentials, as detailed in the linked documentation.\u003c/p\u003e\n"],["\u003cp\u003eYou can explore more code samples for other Google Cloud products using the Google Cloud sample browser.\u003c/p\u003e\n"]]],[],null,["# Getting started with Firestore\n\nCode sample\n-----------\n\n### Kotlin\n\n // Create the client.\n val db = FirestoreOptions.newBuilder()\n .build()\n .service\n\n // Fetch the document reference and data object.\n val docRef = db.collection(collectionName).document(documentName)\n val data = docRef\n .get() // future\n .get() // snapshot\n .data ?: error(\"Document $collectionName:$documentName not found\") // MutableMap\n\n // Print the retrieved data.\n data.forEach { (key, value) -\u003e println(\"$key: $value\") }\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 {Firestore} = require('https://cloud.google.com/nodejs/docs/reference/firestore/latest/overview.html');\n\n // Create a new client\n const firestore = new https://cloud.google.com/nodejs/docs/reference/firestore/latest/firestore/firestore.html();\n\n async function quickstart() {\n // Obtain a document reference.\n const document = firestore.doc('posts/intro-to-firestore');\n\n // Enter new data into the document.\n await document.set({\n title: 'Welcome to Firestore',\n body: 'Hello World',\n });\n console.log('Entered new data into the document');\n\n // Update an existing document.\n await document.update({\n body: 'My first Firestore app',\n });\n console.log('Updated an existing document');\n\n // Read the document.\n const doc = await document.get();\n console.log('Read the document');\n\n // Delete the document.\n await document.delete();\n console.log('Deleted the document');\n }\n quickstart();\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)."]]