Comienza a usar Firestore
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Comienza a usar Firestore
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]