Python 2.7 已終止支援,並將於 2026 年 1 月 31 日
淘汰。淘汰後,您將無法部署 Python 2.7 應用程式,即使貴機構先前曾使用機構政策重新啟用舊版執行階段的部署作業,也無法部署。現有的 Python 2.7 應用程式在
淘汰日期過後,仍會繼續執行並接收流量。建議您
改用系統支援的最新 Python 版本。
以 Datastore 模式使用 Cloud Firestore
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Firestore 是 NoSQL 文件資料庫,專為自動調整資源配置、提供高效能,以及協助輕鬆開發應用程式而打造。這是 Datastore 的最新版本,推出了 Datastore 的多項改進功能。
由於 Datastore 模式中的 Firestore 是針對伺服器用途和 App Engine 進行最佳化,因此建議您將 Datastore 模式中的 Firestore 用於主要由 App Engine 應用程式使用的資料庫。原生模式的 Firestore 最適合用於行動裝置和即時通知用途。如要進一步瞭解 Firestore 模式,請參閱「選擇原生模式或 Datastore 模式」。
搭配 App Engine 使用 Datastore 模式
如何將 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 配額頁面。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間: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"]],["上次更新時間: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."]]