Upsert batch
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Lakukan upsert batch.
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis document provides code samples demonstrating how to perform a batch upsert operation in Google Cloud Datastore mode across various programming languages.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples show how to create and manage entities with properties like category, completion status, priority, and description within the Datastore.\u003c/p\u003e\n"],["\u003cp\u003eTo perform the batch upsert operation, multiple tasks or entities are prepared and then processed together via \u003ccode\u003eUpsert\u003c/code\u003e or \u003ccode\u003ePutMulti\u003c/code\u003e functions that are available within the respective programming languages.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples include instructions on setting up authentication via Application Default Credentials and accessing relevant API documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe page suggests consulting the Google Cloud sample browser for additional code samples related to Datastore and other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Batch upsert\n\nPerform a batch upsert.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Entities, Properties, and Keys](/datastore/docs/concepts/entities)\n\nCode sample\n-----------\n\n### C#\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 var taskList = new[]\n {\n new Entity()\n {\n Key = _keyFactory.CreateIncompleteKey(),\n [\"category\"] = \"Personal\",\n [\"done\"] = false,\n [\"priority\"] = 4,\n [\"description\"] = \"Learn Cloud Datastore\"\n },\n new Entity()\n {\n Key = _keyFactory.CreateIncompleteKey(),\n [\"category\"] = \"Personal\",\n [\"done\"] = \"false\",\n [\"priority\"] = 5,\n [\"description\"] = \"Integrate Cloud Datastore\"\n }\n };\n var keyList = _db.Upsert(taskList[0], taskList[1]);\n\n### Go\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 tasks := []*Task{\n \t{\n \t\tCategory: \"Personal\",\n \t\tDone: false,\n \t\tPriority: 4,\n \t\tDescription: \"Learn Cloud Datastore\",\n \t},\n \t{\n \t\tCategory: \"Personal\",\n \t\tDone: false,\n \t\tPriority: 5,\n \t\tDescription: \"Integrate Cloud Datastore\",\n \t},\n }\n keys := []*datastore.Key{\n \tdatastore.IncompleteKey(\"Task\", nil),\n \tdatastore.IncompleteKey(\"Task\", nil),\n }\n\n keys, err := client.PutMulti(ctx, keys, tasks)\n\n### Java\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 FullEntity\u003cIncompleteKey\u003e task1 =\n FullEntity.newBuilder(keyFactory.newKey())\n .set(\"category\", \"Personal\")\n .set(\"done\", false)\n .set(\"priority\", 4)\n .set(\"description\", \"Learn Cloud Datastore\")\n .build();\n FullEntity\u003cIncompleteKey\u003e task2 =\n Entity.newBuilder(keyFactory.newKey())\n .set(\"category\", \"Personal\")\n .set(\"done\", false)\n .set(\"priority\", 5)\n .set(\"description\", \"Integrate Cloud Datastore\")\n .build();\n List\u003cEntity\u003e tasks = datastore.add(task1, task2);\n Key taskKey1 = tasks.get(0).getKey();\n Key taskKey2 = tasks.get(1).getKey();\n\n### Node.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 const taskKey1 = this.datastore.key(['Task', 1]);\n const taskKey2 = this.datastore.key(['Task', 2]);\n\n const task1 = {\n category: 'Personal',\n done: false,\n priority: 4,\n description: 'Learn Cloud Datastore',\n };\n\n const task2 = {\n category: 'Work',\n done: false,\n priority: 8,\n description: 'Integrate Cloud Datastore',\n };\n\n const entities = [\n {\n key: taskKey1,\n data: task1,\n },\n {\n key: taskKey2,\n data: task2,\n },\n ];\n\n await datastore.upsert(entities);\n // Tasks inserted successfully.\n\n### PHP\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 $result = $datastore-\u003eupsertBatch($tasks);\n\n### Python\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 # For help authenticating your client, visit\n # https://cloud.google.com/docs/authentication/getting-started\n 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()\n\n task1 = https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.entity.Entity.html(client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_key(\"Task\", 1))\n\n task1.update(\n {\n \"category\": \"Personal\",\n \"done\": False,\n \"priority\": 4,\n \"description\": \"Learn Cloud Datastore\",\n }\n )\n\n task2 = https://cloud.google.com/python/docs/reference/datastore/latest/.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.entity.Entity.html(client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_key(\"Task\", 2))\n\n task2.update(\n {\n \"category\": \"Work\",\n \"done\": False,\n \"priority\": 8,\n \"description\": \"Integrate Cloud Datastore\",\n }\n )\n\n client.https://cloud.google.com/python/docs/reference/datastore/latest/google.cloud.datastore.client.Client.html#google_cloud_datastore_client_Client_put_multi([task1, task2])\n\n### Ruby\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 task_1 = datastore.entity \"Task\" do |t|\n t[\"category\"] = \"Personal\"\n t[\"done\"] = false\n t[\"priority\"] = 4\n t[\"description\"] = \"Learn Cloud Datastore\"\n end\n\n task_2 = datastore.entity \"Task\" do |t|\n t[\"category\"] = \"Personal\"\n t[\"done\"] = false\n t[\"priority\"] = 5\n t[\"description\"] = \"Integrate Cloud Datastore\"\n end\n\n tasks = datastore.save task_1, task_2\n task_key_1 = tasks[0].key\n task_key_2 = tasks[1].key\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=datastore)."]]