Java 8 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 Java 8 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署,也无法部署。现有的 Java 8 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 Java 版本。
使用 Datastore 模式 Cloud Firestore
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Firestore 是一个 NoSQL 文档数据库,能够自动扩缩、具备出色的性能,并且易于进行应用开发。Firestore 是 Datastore 的最新版本;与 Datastore 相比,这个新版本引入了多项改进功能。
由于 Datastore 模式 Firestore 针对服务器用例和 App Engine 进行了优化,因此,对于主要将由 App Engine 应用使用的数据库,我们建议使用 Datastore 模式 Firestore。原生模式 Firestore 最适合移动和实时通知用例。如需详细了解 Firestore 模式,请参阅选择原生模式或 Datastore 模式。
将 Datastore 模式与 App Engine 结合使用
如需将 Datastore 模式与 App Engine 搭配使用,请执行以下操作:
如果您尚未这样做,请创建数据库并选择“Datastore 模式 Firestore”。
您可以将现有的 Datastore 数据库与 App Engine 应用搭配使用。这些现有数据库将自动升级为 Datastore 模式 Firestore。
在您的应用中,通过将库添加到应用的依赖项文件中,将 Datastore 声明为依赖项。
使用 Google Cloud 客户端库读取和写入实体以及查询数据。
配置索引
Datastore 模式使用索引来处理应用执行的每个查询。每当实体更改时,这些索引都会更新,因此在应用执行查询时,系统可以快速返回结果。
Datastore 模式会自动创建单属性索引,用于简单类型的查询。对于包含多个属性的复杂查询,您需要在应用的 index.yaml
文件中配置复合索引。
App Engine 开发服务器将使用运行测试所需的复合索引更新 index.yaml
文件。同样,Datastore 模式模拟器可以在您运行测试时生成索引。
如果您不运行本地测试或测试不包含复杂查询,您还可以手动将索引添加到应用的 index.yaml
文件。
设置数据库权限
默认情况下,您的应用拥有对Google Cloud 项目中的 Datastore 模式和 Firestore 数据库执行读写操作所需的所有权限。
为了管理这些权限,每个 App Engine 应用都会使用一个默认服务账号,该账号提供对应用所属项目中的 Datastore 模式和 Firestore 数据库的所有读写权限。您可以更改默认服务账号的权限,但您的应用可能会失去访问权限,除非您分配了拥有所需权限的 IAM 角色。
如需了解如何允许其他用户、应用或项目访问数据库,请参阅访问数据库。
使用 Datastore 模式模拟器进行本地测试
Java 版 Google Cloud CLI 包含一个本地开发服务器,用于在您的计算机上测试您的应用。本地开发服务器会模拟 App Engine Java 运行时环境及其所有服务,包括 Datastore 模式。
开发服务器可以为您的应用所需的 Datastore 模式索引生成配置(根据应用在测试期间执行的查询确定)。
价格、配额和限制
Datastore 模式会提供免费配额,但具有每日限制。对于付费账号,存储、读取和写入操作次数不受限制。如需了解详情,请参阅 Datastore 配额页面。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-20。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-20。"],[[["\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."]]