Python 2.7 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 Python 2.7 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 Python 2.7 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 Python 版本。
使用 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。
使用 Cloud NDB
在 Datastore 模式数据库中创建、检索和管理实体。
如果您计划将 Python 2 应用升级到 Python 3,则有以下几种选择:
如需了解其他资源以及有关从使用 App Engine NDB 的 Python 2 webapp
应用迁移到启用了 App Engine NDB 的等效 Python 3 Flask 应用的示例,请参阅“Python 3 的捆绑服务”页面。
配置索引
Datastore 模式使用索引来处理应用执行的每个查询。每当实体更改时,这些索引都会更新,因此在应用执行查询时,系统可以快速返回结果。
Datastore 模式会自动创建单属性索引,用于简单类型的查询。对于包含多个属性的复杂查询,您需要在应用的 index.yaml
文件中配置复合索引。
App Engine 开发服务器将使用运行测试所需的复合索引更新 index.yaml
文件。同样,Datastore 模式模拟器可以在您运行测试时生成索引。
如果您不运行本地测试或测试不包含复杂查询,您还可以手动将索引添加到应用的 index.yaml
文件。
设置数据库权限
默认情况下,您的应用拥有对Google Cloud 项目中的 Datastore 模式和 Firestore 数据库执行读写操作所需的所有权限。
为了管理这些权限,每个 App Engine 应用都会使用一个默认服务账号,该账号提供对应用所属项目中的 Datastore 模式和 Firestore 数据库的所有读写权限。您可以更改默认服务账号的权限,但您的应用可能会失去访问权限,除非您分配了拥有所需权限的 IAM 角色。
如需了解如何允许其他用户、应用或项目访问数据库,请参阅访问数据库。
价格、配额和限制
Datastore 模式会提供免费配额,但具有每日限制。对于付费账号,存储、读取和写入操作次数不受限制。如需了解详情,请参阅 Datastore 配额页面。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-04。
[[["易于理解","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-09-04。"],[[["\u003cp\u003eFirestore, a NoSQL document database, is designed for automatic scaling, high performance, and easy application development, representing an evolution from 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 tailored for mobile and real-time notifications.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine apps can utilize Firestore in Datastore mode, and existing Datastore databases can be automatically upgraded to this mode, facilitating the management of entities using Cloud NDB.\u003c/p\u003e\n"],["\u003cp\u003eDatastore mode employs indexes for every query, automatically creating single-property indexes, while composite indexes for complex queries need manual configuration in the \u003ccode\u003eindex.yaml\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eBy default, App Engine apps possess full read and write permissions to Datastore mode and Firestore databases via a default service account, but these permissions can be modified, requiring an IAM role with specific permissions to maintain access.\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).\n2. [Use Cloud NDB](/appengine/migration-center/standard/python/migrate-to-cloud-ndb))\n\n to create, retrieve, and manage entities in your Datastore mode\n database.\n\nIf you are planning to upgrade your Python 2 app to Python 3, you have a few options:\n\n- If your Python 2 app uses [App Engine NDB](/appengine/docs/legacy/standard/python/ndb)\n to interact with Datastore, we recommend\n [migrating to Cloud NDB](/appengine/migration-center/standard/python/migrate-to-cloud-ndb)\n instead of the Datastore mode client library as the former\n provides a much more similar user experience.\n\n- You can also choose to port your Python 2 app that uses App Engine\n NDB to Python 3 first and *then* migrate to Cloud NDB. To learn how to access\n App Engine NDB in Python 3, see the [Accessing App Engine bundled\n services for Python 3 page](/appengine/docs/standard/python3/services/access).\n\nFor additional resources plus an example of migrating from a Python 2 `webapp`\napp using App Engine NDB to an equivalent Python 3 Flask app with App Engine NDB\nenabled, see the [bundled services for Python 3\npage](/appengine/docs/standard/python3/services/access#example_app_engine_ndb).\n\nConfiguring indexes\n-------------------\n\nDatastore mode uses\n[indexes](/datastore/docs/concepts/indexes)\nfor every query your application makes. The indexes are updated whenever an\nentity changes, so the results can be returned quickly when the app makes a\nquery.\n\nDatastore mode automatically creates single-property indexes for use with\nsimple types of queries. For complex queries that include multiple properties,\nyou'll need to configure composite indexes in your app's `index.yaml` file.\n\nThe App Engine development server will update your `index.yaml` file\nwith the composite indexes needed to run your tests. Similarly, the\n[Datastore mode emulator can generate indexes](/datastore/docs/tools)\nwhen you run tests.\n\nYou can also add the indexes to your app's\n`index.yaml` file [manually](/appengine/docs/legacy/standard/python/config/indexref#automatic) if you do not run local\ntests or your tests do not include complex queries.\n\nSetting database permissions\n----------------------------\n\nBy default, your app has all the permissions required to read and write to\nDatastore mode and Firestore databases in your\nGoogle Cloud project.\n\nTo manage these permissions, each App Engine app uses a [default service\naccount](/appengine/docs/legacy/standard/python/service-account)\nthat gives full read and write access to Datastore mode\nand Firestore databases in the same project as the app. You can\n[change the permissions of the default service\naccount](/appengine/docs/legacy/standard/python/access-control#modify-service-account),\nbut your app may lose access unless you assign an IAM role with the\n[required permissions](/datastore/docs/access/iam#required_permissions).\n\nFor information about allowing other users, apps, or projects to access a database, see\n[Accessing your database](/datastore/docs/activate).\n\nPricing, quotas, and limits\n---------------------------\n\nDatastore mode offers a free quota with daily limits. Paid\naccounts offer unlimited storage, read, and write operations. More information\nis available on the [Datastore Quotas](/appengine/docs/legacy/standard/python/quotas#Datastore) page."]]