Borrar tarea
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Borra una tarea.
Explora más
Para obtener documentación en la que se incluye esta muestra de código, consulta lo siguiente:
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 document provides code samples and instructions for deleting a task entity in Datastore mode across multiple programming languages.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples demonstrate how to delete tasks using the Datastore client libraries in C#, Go, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach language section includes links to the Datastore mode client libraries documentation and the respective API reference documentation for more in-depth information.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication for Datastore mode is handled by setting up Application Default Credentials, with instructions provided for local development environments.\u003c/p\u003e\n"],["\u003cp\u003eThe ID, Project ID or key of the task is required for most of the code samples in order to properly delete the task.\u003c/p\u003e\n"]]],[],null,["Delete a task.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Getting started with the Firestore in Datastore mode API](/datastore/docs/datastore-api-tutorial)\n\nCode sample \n\nC#\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode C# API\nreference documentation](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest).\n\n\nTo authenticate to Datastore mode, 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 /// \u003csummary\u003e\n /// Deletes a task entity.\n /// \u003c/summary\u003e\n /// \u003cparam name=\"id\"\u003eThe ID of the task entity as given by Key.\u003c/param\u003e\n void DeleteTask(long id)\n {\n _db.Delete(_keyFactory.CreateKey(id));\n }\n\nGo\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Go API\nreference documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest).\n\n\nTo authenticate to Datastore mode, 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\"log\"\n\n \t\"cloud.google.com/go/datastore\"\n )\n\n // DeleteTask deletes the task with the given ID.\n func DeleteTask(projectID string, taskID int64) error {\n \tctx := context.Background()\n \tclient, err := datastore.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/index.html#cloud_google_com_go_datastore_Client_NewClient(ctx, projectID)\n \tif err != nil {\n \t\tlog.Fatalf(\"Could not create datastore client: %v\", err)\n \t}\n \treturn client.Delete(ctx, datastore.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/index.html#cloud_google_com_go_datastore_Key_IDKey(\"Task\", taskID, nil))\n }\n\nJava\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Java API\nreference documentation](https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/history).\n\n\nTo authenticate to Datastore mode, 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 /**\n * Deletes a task entity.\n *\n * @param id The ID of the task entity as given by {@link Key#id()}\n * @throws DatastoreException if the delete fails\n */\n void deleteTask(long id) {\n datastore.delete(keyFactory.newKey(id));\n }\n\nNode.js\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Node.js API\nreference documentation](https://cloud.google.com/nodejs/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, 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 async function deleteTask(taskId) {\n const taskKey = datastore.key(['Task', datastore.int(taskId)]);\n\n await datastore.delete(taskKey);\n console.log(`Task ${taskId} deleted successfully.`);\n }\n\nPHP\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode PHP API\nreference documentation](https://googleapis.github.io/google-cloud-php/#/docs/cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, 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 use Google\\Cloud\\Datastore\\DatastoreClient;\n\n /**\n * Delete a task with a given id.\n *\n * @param string $projectId The Google Cloud project ID.\n * @param string $taskId\n */\n function delete_task(string $projectId, string $taskId)\n {\n $datastore = new DatastoreClient(['projectId' =\u003e $projectId]);\n\n $taskKey = $datastore-\u003ekey('Task', $taskId);\n $datastore-\u003edelete($taskKey);\n\n printf('Task %d deleted successfully.' . PHP_EOL, $taskId);\n }\n\nPython\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Python API\nreference documentation](https://cloud.google.com/python/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, 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 from google.cloud import https://cloud.google.com/python/docs/reference/datastore/latest/\n\n def delete_task(client: https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html, task_id: str | int):\n # Create a key for an entity of kind \"Task\", and with the supplied\n # `task_id` as its Id\n key = client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_key(\"Task\", task_id)\n # Use that key to delete its associated document, if it exists\n client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_delete(key)\n\nRuby\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Ruby API\nreference documentation](/ruby/docs/reference/google-cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, 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 def delete_task task_id\n require \"google/cloud/datastore\"\n\n datastore = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore.html.https://cloud.google.com/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore.html\n\n task = datastore.find \"Task\", task_id\n\n datastore.delete task\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=datastore)."]]