Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menyimpan dan membuat kueri data di Firestore dalam mode Datastore
Halaman ini menunjukkan cara menyimpan dan membuat kueri data di Firestore dalam mode Datastore menggunakan konsol Google Cloud .
Sebelum memulai
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Jika Anda bukan pemilik project, akun Anda memerlukan
izin berikut untuk menyelesaikan panduan memulai ini:
Akun Anda memerlukan
peran Pemilik Datastore
yang berisi izin datastore.databases.create
yang diperlukan untuk membuat instance mode Datastore.
Mode Datastore memerlukan aplikasi App Engine yang aktif.
Jika project tidak memiliki aplikasi, panduan memulai ini akan membuatkannya
untuk Anda. Dalam hal ini, Anda memerlukan
izin appengine.applications.create. Pemilik project
dapat menetapkan izin ini dengan
peran kustom IAM.
Buat database
Untuk membuat instance database baru, buka bagian Datastore di konsol Google Cloud : Buka halaman Datastore
Pilih mode database.
Saat membuat database Firestore baru, Anda memiliki opsi untuk menggunakan
Firestore dalam Mode Native atau mode Datastore. Anda tidak dapat menggunakan kedua
mode dalam project yang sama.
Pilih salah satu opsi database:
Firestore dalam Mode Native
Direkomendasikan untuk aplikasi seluler dan web. Untuk mulai menggunakan Firestore, lanjutkan di Panduan Memulai Firestore.
Firestore dalam Mode Datastore
Direkomendasikan untuk arsitektur aplikasi dengan server backend.
Pilih lokasi database. Mode Datastore mendukung lokasi multi-region dan regional.
Lokasi multi-region memaksimalkan ketersediaan dan ketahanan. Lokasi
regional menawarkan latensi tulis yang lebih rendah. Untuk mempelajari jenis lokasi lebih lanjut, lihat Lokasi mode Datastore.
Lokasi berlaku untuk database mode Datastore dan aplikasi App Engine untuk project Google Cloud Anda.
Klik Buat database. Setelah inisialisasi database selesai, konsol
Google Cloud akan mengarahkan Anda ke halaman Entitas Datastore.
Menyimpan data
Buka halaman Entity Datastore di konsol Google Cloud .
Halaman ini memungkinkan Anda menyimpan, membuat kueri, memperbarui, dan menghapus data.
Klik Buat entity.
Di halaman Create an entity, gunakan [default] untuk Namespace.
Ketik Task di kolom Jenis. Biarkan ID utama ditetapkan ke
nilai default Numeric ID (auto-generated).
Di bagian Properti, gunakan tombol Tambahkan properti untuk menambahkan properti berikut:
Nama
Jenis
Nilai
Terindeks
deskripsi
String
Pelajari Datastore.
dibuat
Tanggal dan waktu
(tanggal hari ini)
✓
done
Boolean
Salah
✓
Halaman kreasi Anda sekarang akan terlihat seperti ini:
Klik Buat. Konsol menampilkan entitas Task yang baru saja Anda buat.
Anda baru saja menyimpan data di database.
Menjalankan kueri
Database mode Datastore mendukung kueri data menurut jenis atau menurut
Google Query Language (GQL). Petunjuk di bawah akan memandu Anda menggunakan keduanya
untuk membuat kueri database.
Menjalankan kueri jenis
Klik Kueri menurut jenis.
Pilih Task sebagai jenisnya.
Hasil kueri menampilkan entitas Task yang Anda buat.
Selanjutnya, tambahkan klausa kueri untuk membatasi hasil ke entity yang memenuhi kriteria tertentu:
Klik Tambahkan klausa kueri.
Di menu drop-down, pilih WHERE, done, ==, boolean, dan
false.
Klik Run. Hasilnya menunjukkan entity Task yang Anda
buat karena nilai done-nya adalah false.
Sekarang ubah klausa kueri menjadi WHERE, done, ==, boolean, dan
true. Klik Run. Hasilnya tidak menyertakan entity Task yang Anda buat, karena nilai done-nya bukan true.
Menjalankan kueri GQL
Klik Kueri menurut GQL.
Masukkan SELECT * FROM Task sebagai kueri. Perhatikan bahwa Task peka huruf besar/kecil.
Klik Run query.
Hasil kueri menampilkan entitas Task yang Anda buat.
Tambahkan filter kueri untuk membatasi hasil ke entity yang memenuhi kriteria tertentu:
Jalankan kueri seperti SELECT * FROM Task WHERE done=false. Perhatikan bahwa Task
dan done peka huruf besar/kecil.
Hasilnya menunjukkan entity Task yang Anda buat, karena nilai done-nya adalah false.
Sekarang jalankan kueri seperti SELECT * FROM Task WHERE done=true. Hasilnya tidak menyertakan entity Task yang Anda buat, karena nilai done-nya bukan true.
Pembersihan
Klik Query menurut jenis dan pastikan Task adalah jenis yang dipilih.
Klik Hapus untuk menghapus klausa kueri.
Pilih entitas Task yang Anda buat.
Klik Hapus, lalu konfirmasi bahwa Anda ingin menghapus entity Task.
Bergantung pada ukuran jendela browser, Hapus mungkin ada di menu
more_vertTindakan lainnya. Setelah
dihapus, entitas akan dihapus secara permanen dari database Anda.
Selesai, Anda telah menyelesaikan panduan memulai ini.
[[["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"]],["Terakhir diperbarui pada 2025-08-19 UTC."],[[["\u003cp\u003eThis guide demonstrates how to use the Google Cloud console to store and query data in Firestore's Datastore mode.\u003c/p\u003e\n"],["\u003cp\u003eCreating a Datastore mode instance requires the Datastore Owner role and an active App Engine application, or the \u003ccode\u003eappengine.applications.create\u003c/code\u003e permission.\u003c/p\u003e\n"],["\u003cp\u003eDatastore mode offers multi-region or regional locations, and once set, the database location cannot be changed.\u003c/p\u003e\n"],["\u003cp\u003eData can be stored as entities with properties (name, type, value), and the guide uses a \u003ccode\u003eTask\u003c/code\u003e entity example.\u003c/p\u003e\n"],["\u003cp\u003eData in Datastore can be queried by kind or using Google Query Language (GQL), with support for filtering results based on specific criteria.\u003c/p\u003e\n"]]],[],null,["# Quickstart: Store and query data in Firestore in Datastore mode\n\nStore and query data in Firestore in Datastore mode\n===================================================\n\nThis page shows you how to store and query data in Firestore in Datastore mode using the Google Cloud console.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n If you are **not** the project owner, your account requires the\n following permissions to complete this quickstart:\n\n\n - Your account requires the [**Datastore Owner** role](/iam/docs/understanding-roles#cloud_datastore_roles) which contains the `datastore.databases.create` permission needed to create a Datastore mode instance.\n - Datastore mode requires an active App Engine application. If the project doesn't have an application, this quickstart creates one for you. In that case, you require the `appengine.applications.create` permission. The project owner can assign this permission with an [IAM custom role](/iam/docs/creating-custom-roles).\n\nCreate a database\n-----------------\n\n1. To create a new database instance, open the Datastore section\n in the Google Cloud console: \n\n [Go to the Datastore page](https://console.cloud.google.com/datastore/welcome)\n\n2. Select a database mode.\n\n When you create a new Firestore database, you have the option to use\n Firestore in either Native Mode or Datastore mode. You can't use both\n modes in the same project.\n\n Select from one of the database options:\n - **Firestore in Native Mode**\n\n Recommended for mobile and web apps. To get started with Firestore, continue in the [Firestore Quickstart](/firestore/docs/quickstart).\n - **Firestore in Datastore Mode**\n\n Recommended for app architectures with backend servers.\n\n For more guidance on selecting a database mode and for a feature-by-feature\n comparison, see\n [choosing between Native Mode and Datastore Mode](/datastore/docs/firestore-or-datastore).\n3. Select a database location. Datastore mode supports multi-region\n and regional locations.\n\n A multi-region location maximizes availability and durability. Regional\n locations offer lower write latency. To learn more about location types,\n see [Datastore mode locations](/datastore/docs/locations).\n The location applies to both Datastore mode databases and App Engine apps for\n your Google Cloud project.\n | **Warning:** Once you create your database, you cannot change the location.\n\n Click **Create database**. After your database finishes initializing, the\n Google Cloud console directs you to the Datastore Entities page.\n\nStore data\n----------\n\n1. Go to the Datastore Entities page in the Google Cloud console.\n\n [Go to the Entities page](https://console.cloud.google.com/datastore/entities/query)\n\n This page lets you store, query, update, and delete data.\n2. Click **Create entity**.\n\n3. On the **Create an entity** page, use `[default]` for **Namespace**.\n\n4. Type `Task` in the **Kind** field. Leave **Key identifier** set to the\n default value of `Numeric ID (auto-generated)`.\n\n5. Under **Properties** , use the **Add property** button to add these properties:\n\n Your creation page should now look like this:\n\n \u003cbr /\u003e\n\n6. Click **Create** . The console displays the `Task` entity that you just created.\n\nYou just stored data in your database!\n\nRun a query\n-----------\n\nDatastore mode databases support querying data by kind or by\nGoogle Query Language (GQL). The instructions below walk you through using both\nto query your database.\n\n### Run kind queries\n\n1. Click **Query by kind**.\n2. Select `Task` as the kind.\n\nThe query results show the `Task` entity that you created.\n\nNext, add a query clause to restrict the results to entities that meet specific\ncriteria:\n\n1. Click **Add query clause**.\n2. In the dropdown lists, select `WHERE`, `done`, `==`, **boolean** , and **false**.\n3. Click **Run** . The results show the `Task` entity that you created since its `done` value is `false`.\n4. Now change the query clause to `WHERE`, `done`, `==`, **boolean** , and **true** . Click **Run** . The results do not include the `Task` entity that you created, because its `done` value is not `true`.\n\n### Run GQL queries\n\n1. Click **Query by GQL**.\n2. Enter `SELECT * FROM Task` as the query. Note that `Task` is case sensitive.\n3. Click **Run query**.\n\nThe query results show the `Task` entity that you created.\n| **Tip**\n|\n| The GQL query editor supports autocompletion for kinds: When you\n| need to type a kind name, press Ctrl+Space to see a list of the available\n| kinds. Up to 300 alphabetically sorted kinds can appear in the list. For\n| better matches of kinds, type one or more characters.\n\nAdd a query filter to restrict the results to entities that meet\nspecific criteria:\n\n1. Run a query such as `SELECT * FROM Task WHERE done=false`. Note that `Task` and `done` are case sensitive. The results show the `Task` entity that you created, since its `done` value is `false`.\n2. Now run a query such as `SELECT * FROM Task WHERE done=true`. The results do not include the `Task` entity that you created, because its `done` value is not `true`.\n\nClean up\n--------\n\n1. Click **Query by kind** and ensure `Task` is the selected kind.\n2. Click **Clear** to remove any query clauses.\n3. Select the `Task` entity that you created.\n4. Click **Delete** , and then confirm you want to delete the `Task` entity. Depending on the size of the browser window, **Delete** might be under the more_vert **More actions** menu. Once deleted, the entity is permanently removed from your database.\n\nThat's it, you completed this quickstart!\n\nWhat's next\n-----------\n\n- Learn more about [Datastore Queries](/datastore/docs/concepts/queries).\n- Learn more about [Datastore mode](/datastore/docs) databases.\n\n\u003cbr /\u003e"]]