Erste Schritte mit Firestore
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Erste Schritte mit Firestore
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"]],[],[[["\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)."]]