Menggunakan Cloud Firestore dalam Mode Datastore
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Firestore adalah database dokumen NoSQL yang dibangun untuk penskalaan otomatis, performa tinggi, dan kemudahan pengembangan aplikasi. Ini adalah versi terbaru Datastore dan memperkenalkan beberapa peningkatan pada Datastore.
Karena Firestore dalam mode Datastore yang dioptimalkan untuk kasus penggunaan server dan untuk App Engine, sebaiknya gunakan Firestore dalam mode Datastore untuk database yang akan digunakan terutama oleh aplikasi App Engine. Firestore dalam mode Native paling berguna untuk kasus penggunaan notifikasi real-time dan seluler. Untuk mengetahui informasi selengkapnya tentang mode Firestore, lihat Memilih antara Mode Native dan mode Datastore.
Menggunakan mode Datastore dengan App Engine
Untuk menggunakan mode Datastore dengan App Engine:
Jika belum melakukannya, buat database lalu pilih Firestore dalam mode Datastore.
Anda dapat menggunakan database Datastore yang sudah ada dengan aplikasi App Engine. Database yang sudah ada ini akan otomatis di-upgrade ke Firestore dalam mode Datastore.
Di aplikasi Anda, deklarasikan Datastore sebagai dependensi dengan menambahkan library ke file dependensi aplikasi Anda.
Gunakan Library Klien Google Cloud untuk membaca dan menulis entity serta membuat kueri data.
Mengonfigurasi indeks
Mode Datastore menggunakan indeks untuk setiap kueri yang dibuat aplikasi Anda. Indeks diperbarui setiap kali entity berubah, sehingga hasilnya dapat ditampilkan dengan cepat saat aplikasi membuat kueri.
Mode Datastore secara otomatis membuat indeks properti tunggal untuk digunakan dengan jenis kueri yang sederhana. Untuk kueri kompleks yang mencakup beberapa properti, Anda harus mengonfigurasi indeks komposit di file index.yaml
aplikasi.
Server pengembangan App Engine akan memperbarui file index.yaml
Anda dengan indeks komposit yang diperlukan untuk menjalankan pengujian. Demikian pula, emulator mode Datastore dapat membuat indeks saat Anda menjalankan pengujian.
Anda juga dapat menambahkan indeks ke file index.yaml
aplikasi secara manual jika tidak menjalankan pengujian lokal atau pengujian tidak menyertakan kueri yang kompleks.
Menetapkan izin database
Secara default, aplikasi Anda memiliki semua izin yang diperlukan untuk membaca dan menulis ke mode Datastore dan database Firestore di projectGoogle Cloud .
Untuk mengelola izin ini, setiap aplikasi App Engine menggunakan akun layanan default yang memberikan akses baca dan tulis penuh ke mode Datastore dan database Firestore dalam project yang sama dengan aplikasi. Anda dapat mengubah izin akses dari akun layanan default, tetapi aplikasi Anda dapat kehilangan akses kecuali jika Anda menetapkan peran IAM dengan izin yang diperlukan.
Untuk mengetahui informasi tentang cara mengizinkan pengguna, aplikasi, atau project lain mengakses database, lihat Mengakses database.
Menggunakan emulator mode Datastore untuk pengujian lokal
Google Cloud CLI untuk Java mencakup server pengembangan lokal untuk menguji aplikasi Anda di komputer. Server pengembangan lokal mengemulasikan lingkungan runtime Java App Engine dan semua layanannya, termasuk mode Datastore.
Server pengembangan menghasilkan konfigurasi untuk indeks mode Datastore yang diperlukan aplikasi Anda, yang ditentukan dari kueri yang dijalankannya saat Anda mengujinya.
Harga, kuota, dan batas
Mode Datastore menawarkan kuota gratis dengan batas harian. Akun berbayar menawarkan penyimpanan tak terbatas, operasi baca, dan tulis. Informasi selengkapnya tersedia di halaman Kuota Datastore.
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.
Terakhir diperbarui pada 2025-09-04 UTC.
[[["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-09-04 UTC."],[[["\u003cp\u003eFirestore is a NoSQL document database designed for automatic scaling, high performance, and ease of development, with improvements over its predecessor, Datastore.\u003c/p\u003e\n"],["\u003cp\u003eFirestore offers two modes: Datastore mode, which is optimized for server use cases and App Engine, and Native mode, which is designed for mobile and real-time notifications.\u003c/p\u003e\n"],["\u003cp\u003eDatastore mode utilizes indexes for each query, automatically generating single-property indexes and requiring composite indexes for complex queries, which can be managed via the \u003ccode\u003eindex.yaml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine apps using Datastore mode have default permissions to read and write to the database, managed by a service account, but these permissions can be modified, though it could cause access issues if the proper role isn't assigned.\u003c/p\u003e\n"],["\u003cp\u003eDatastore mode offers a free quota with daily limits, with paid accounts providing unlimited storage and read/write operations.\u003c/p\u003e\n"]]],[],null,["# Using Cloud Firestore in Datastore Mode\n\nFirestore is a NoSQL document database built for automatic scaling,\nhigh performance, and ease of application development. It is the newest version\nof Datastore and introduces several improvements over\nDatastore.\n\nBecause Firestore in [Datastore mode](/datastore/docs)\nis optimized for server use cases and for\nApp Engine, we recommend using Firestore in\nDatastore mode for databases that will be used primarily by\nApp Engine apps. Firestore in Native mode is most useful for\nmobile and real-time notification use cases. For more information about\nFirestore modes, see [Choosing between Native Mode and\nDatastore mode](/datastore/docs/firestore-or-datastore).\n\nUsing Datastore mode with App Engine\n------------------------------------\n\nTo use Datastore mode with App Engine:\n\n1. If you haven't already done so,\n [create a database](/datastore/docs/store-query-data#create_a_database)\n and choose Firestore in Datastore mode.\n\n You can use existing Datastore databases with App Engine\n apps. These existing databases [will be automatically upgraded to\n Firestore in Datastore\n mode](/datastore/docs/upgrade-to-firestore).\n\n\n 1. In your app, declare Datastore as a dependency\n\n by [adding the library to your app's dependencies\n file](/datastore/docs/reference/libraries#client-libraries-install-java).\n\n \u003cbr /\u003e\n\n 2. Use the Google Cloud Client Library to\n [read and write entities](/datastore/docs/concepts/entities)\n and to [query data](/datastore/docs/concepts/queries).\n\n Configuring indexes\n -------------------\n\n Datastore mode uses\n [indexes](/datastore/docs/concepts/indexes)\n for every query your application makes. The indexes are updated whenever an\n entity changes, so the results can be returned quickly when the app makes a\n query.\n\n Datastore mode automatically creates single-property indexes for use with\n simple types of queries. For complex queries that include multiple properties,\n you'll need to configure composite indexes in your app's `index.yaml` file.\n\n The App Engine development server will update your `index.yaml` file\n with the composite indexes needed to run your tests. Similarly, the\n [Datastore mode emulator can generate indexes](/datastore/docs/tools)\n when you run tests.\n\n You can also add the indexes to your app's\n `index.yaml` file [manually](/appengine/docs/legacy/standard/java/configuring-datastore-indexes-with-index-yaml) if you do not run local\n tests or your tests do not include complex queries.\n\n Setting database permissions\n ----------------------------\n\n By default, your app has all the permissions required to read and write to\n Datastore mode and Firestore databases in your\n Google Cloud project.\n\n To manage these permissions, each App Engine app uses a [default service\n account](/appengine/docs/legacy/standard/java/service-account)\n that gives full read and write access to Datastore mode\n and Firestore databases in the same project as the app. You can\n [change the permissions of the default service\n account](/appengine/docs/legacy/standard/java/access-control#modify-service-account),\n but your app may lose access unless you assign an IAM role with the\n [required permissions](/datastore/docs/access/iam#required_permissions).\n\n For information about allowing other users, apps, or projects to access a database, see\n [Accessing your database](/datastore/docs/activate).\n\n Using the Datastore mode emulator for local testing\n ---------------------------------------------------\n\n The Google Cloud CLI for Java includes a [local development\n server](/appengine/docs/legacy/standard/java/tools/using-local-server) for testing your application on your computer. The local development server emulates the App Engine Java runtime environment and all of its services, including Datastore mode.\n\n \u003cbr /\u003e\n\n The development server generates configuration for Datastore mode\n indexes needed by your application, determined from the queries it performs\n while you are testing it.\n\n Pricing, quotas, and limits\n ---------------------------\n\n Datastore mode offers a free quota with daily limits. Paid\n accounts offer unlimited storage, read, and write operations. More information\n is available on the [Datastore Quotas](/appengine/docs/legacy/standard/java/quotas#Datastore) page."]]