Mengimpor entity admin ke Datastore
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Mengimpor entity admin ke Datastore
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 content provides code samples and instructions for importing admin entities into Datastore using C#, Go, Node.js, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eEach language section offers guidance on using the respective client library for Datastore mode, including how to install and use it.\u003c/p\u003e\n"],["\u003cp\u003eThe content emphasizes the importance of setting up Application Default Credentials for authentication in a local development environment, directing users to the appropriate documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples in each language demonstrate the process of importing entities, including specifying the project ID and the input URL where the data is located.\u003c/p\u003e\n"],["\u003cp\u003eUsers can use the Google Cloud sample browser to find code samples related to other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Import admin entities to Datastore\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\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.html;\n using https://cloud.google.com/dotnet/docs/reference/Google.LongRunning/latest/Google.LongRunning.html;\n using https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.html;\n using System;\n using System.Collections.Generic;\n\n public class ImportEntitiesSample\n {\n public bool ImportEntities(\n string projectId = \"your-project-id\",\n // For information on accepted input URL formats, see\n // https://cloud.google.com/datastore/docs/reference/admin/rpc/google.datastore.admin.v1#google.datastore.admin.v1.ImportEntitiesRequest\n string inputUrl = \"[URL to file containing data]\",\n string kind = \"Task\",\n string namespaceId = \"default\")\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html datastoreAdminClient = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_Create();\n\n IDictionary\u003cstring, string\u003e labels = new Dictionary\u003cstring, string\u003e { { \"cloud_datastore_samples\", \"true\" }, };\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.EntityFilter.html entityFilter = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.EntityFilter.html()\n {\n Kinds = { kind },\n NamespaceIds = { namespaceId }\n };\n\n Operation\u003cEmpty, ImportEntitiesMetadata\u003e response = datastoreAdminClient.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_ImportEntities_Google_Cloud_Datastore_Admin_V1_ImportEntitiesRequest_Google_Api_Gax_Grpc_CallSettings_(projectId, labels, inputUrl, entityFilter);\n\n // Poll until the returned long-running operation is complete\n Operation\u003cEmpty, ImportEntitiesMetadata\u003e completedResponse = response.PollUntilCompleted();\n\n if (completedResponse.IsFaulted)\n {\n Console.WriteLine($\"Error while Importing Entities: {completedResponse.Exception}\");\n throw completedResponse.Exception;\n }\n\n Console.WriteLine($\"Entities imported successfully.\");\n\n return completedResponse.IsCompleted;\n }\n }\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 import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tadmin \"cloud.google.com/go/datastore/admin/apiv1\"\n \t\"cloud.google.com/go/datastore/admin/apiv1/adminpb\"\n )\n\n // entitiesImport imports entities into Datastore.\n func entitiesImport(w io.Writer, projectID, inputURL string) error {\n \t// projectID := \"project-id\"\n \t// inputURL := \"gs://bucket-name/overall-export-metadata-file\"\n \tctx := context.Background()\n \tclient, err := admin.NewDatastoreAdminClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"admin.NewDatastoreAdminClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/admin/apiv1.html#cloud_google_com_go_datastore_admin_apiv1_DatastoreAdminClient_Close()\n\n \treq := &adminpb.ImportEntitiesRequest{\n \t\tProjectId: projectID,\n \t\tInputUrl: inputURL,\n \t}\n \top, err := client.ImportEntities(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"ImportEntities: %w\", err)\n \t}\n \tif err = op.Wait(ctx); err != nil {\n \t\treturn fmt.Errorf(\"Wait: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Entities were imported\\n\")\n \treturn nil\n }\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 {Datastore} = require('https://cloud.google.com/nodejs/docs/reference/datastore/latest/overview.html');\n const datastore = new https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html();\n\n async function importEntities() {\n /**\n * TODO(developer): Uncomment these variables before running the sample.\n */\n // const file = 'YOUR_FILE_NAME';\n\n const [importOperation] = await datastore.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html({file});\n\n // Uncomment to await the results of the operation.\n // await importOperation.promise();\n\n // Or cancel the operation.\n await importOperation.cancel();\n\n // You may also choose to include only specific kinds and namespaces.\n const [specificImportOperation] = await datastore.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html({\n file,\n kinds: ['Employee', 'Task'],\n namespaces: ['Company'],\n });\n\n // Uncomment to await the results of the operation.\n // await specificImportOperation.promise();\n\n // Or cancel the operation.\n await specificImportOperation.cancel();\n }\n\n importEntities();\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 def import_entities(project_id, input_url):\n \"\"\"Imports entities into Datastore.\"\"\"\n # project_id := \"project-id\"\n # input_url := \"gs://bucket-name/overall-export-metadata-file\"\n client = DatastoreAdminClient()\n\n op = client.import_entities({\"project_id\": project_id, \"input_url\": input_url})\n response = op.result(timeout=300)\n\n print(\"Entities were imported\\n\")\n return response\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 # project_id = \"project-id\"\n # input_url = \"gs://bucket-name/overall-export-metadata-file\"\n op = client.import_entities project_id: project_id, input_url: input_url\n\n op.wait_until_done!\n raise op.error.message if op.error?\n\n response = op.response\n # Process the response.\n\n metadata = op.metadata\n # Process the metadata.\n\n puts \"Entities were imported\"\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)."]]