Introduzione a Firestore
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Introduzione a Firestore
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","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)."]]