[[["易于理解","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-03。"],[[["\u003cp\u003eFirestore offers two database modes: Native mode, which is a document database with real-time updates and mobile/web client libraries, and Datastore mode, which is backwards-compatible with Datastore and removes its previous limitations.\u003c/p\u003e\n"],["\u003cp\u003eNative mode is recommended for new mobile and web applications due to its real-time capabilities and offline support, while Datastore mode is suggested for new server projects to utilize established Datastore architectures with improved scalability.\u003c/p\u003e\n"],["\u003cp\u003eNative mode supports Firestore API requests, and it uses a document database model organized into documents and collections, while Datastore mode supports Datastore API requests and uses entities organized into kinds and entity groups.\u003c/p\u003e\n"],["\u003cp\u003eBoth modes offer a strongly consistent storage layer and use the same pricing and location structure, however Native mode supports Firestore client libraries and real-time updates while Datastore does not.\u003c/p\u003e\n"],["\u003cp\u003eYou can create multiple Firestore databases in a single project, each with its own selected mode, and it is possible to switch between Native and Datastore modes if the database is empty, using the \u003ccode\u003egcloud\u003c/code\u003e command or REST API.\u003c/p\u003e\n"]]],[],null,["# Choosing between Native mode and Datastore mode\n\nWhen you create a Firestore database, you must choose between two\nmodes: Native mode or Datastore mode. This page explains the difference between\nthe two modes.\n\nChoose a database mode\n----------------------\n\nWhen you create a new Firestore database, you must select a database mode.\nYou can have both Native mode and Datastore mode databases in the same project,\nbut each database will be of a single type.\n\nWe recommend the following when choosing a database mode:\n\n- **Use Firestore in Native mode for all new applications (server, mobile, and web).**\n\n Firestore in Native mode uses a document-based data model that\n aligns with industry standards. In addition to a strongly consistent and\n scalable database, Firestore in Native mode provides real-time\n data syncing and backend-as-as-service features.\n- **Use Firestore in Datastore mode if your app depends on the Datastore API.**\n\n Datastore Mode is fully supported and is recommended for applications with a\n dependency on the Datastore API. Native mode and Datastore mode share an\n underlying storage layer with the same availability, consistency, and\n scaling capabilities.\n\nFirestore in Native mode\n------------------------\n\nFirestore is the next major version of Datastore and\na re-branding of the product. Taking the best of Datastore and the [Firebase\nRealtime Database](https://firebase.google.com/docs/database/rtdb-vs-firestore),\nFirestore is a NoSQL document database built for automatic scaling,\nhigh performance, and ease of application development.\n\nFirestore introduces the following features:\n\n- A strongly consistent storage layer\n- A collection and document data model\n- Real-time updates\n- Mobile and Web client libraries\n\nFirestore is backwards compatible with Datastore, but the new\ndata model, real-time updates, and mobile and web client library features are\nnot. To access all Firestore features, you must use\nFirestore in Native mode.\n\nFirestore in Datastore mode\n---------------------------\n\nFirestore in Datastore mode uses Datastore system behavior but\naccesses Firestore's storage layer, removing the following\nDatastore limitations:\n\n- All Datastore queries are now strongly consistent, unless you explicitly request [eventual consistency](/datastore/docs/reference/data/rpc/google.datastore.v1#google.datastore.v1.ReadOptions).\n- Queries in transactions are no longer required to be ancestor queries.\n- Transactions are no longer limited to 25 entity groups.\n- Writes to an entity group are no longer limited to 1 per second.\n\nDatastore mode disables Firestore features that are not\ncompatible with Datastore:\n\n- The project will accept Datastore API requests and deny Firestore API requests.\n- The project will use Datastore indexes instead of Firestore indexes.\n- You can use Datastore client libraries with this project but not Firestore client libraries.\n- Firestore real-time capabilities will not be available.\n- In the Google Cloud console, the database will use the Datastore viewer.\n\nPricing and locations\n---------------------\n\nNative mode and Datastore mode databases use the same pricing structure and are\navailable in the same locations. Pricing and locations are described in\ndetail in the following pages:\n\n#### Firestore in Native mode\n\n- [Firestore pricing](/firestore/pricing)\n- [Firestore locations](/firestore/docs/locations)\n\n#### Firestore in Datastore mode\n\n- [Firestore in Datastore mode pricing](/datastore/pricing)\n- [Firestore in Datastore mode locations](/datastore/docs/locations)\n\n### Feature comparison\n\nThe following table compares the system behavior of the database modes:\n\nCreate a new database\n---------------------\n\nYou can create a new Firestore database in either Native mode or Datastore mode. This choice does not depend on the modes of any existing databases in your project.\nSee [Create and manage databases](/datastore/docs/manage-databases) for more info.\n\nChange between Native mode and Datastore mode\n---------------------------------------------\n\nIf your database is empty, you can change between Native mode and Datastore mode.\n| **Warning:** Mode changes are only allowed if the database is empty of all entities and documents. A mode change takes a few minutes to take effect during which time the database will reject writes.\n\nChange database to **Native mode**: \n\n### gcloud\n\nUse the [gcloud firestore databases update](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/update) command to change your database to Native mode. \n\n gcloud firestore databases update --type=firestore-native --database='\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e'\n\nReplace \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e with the ID of your database.\n\n### rest\n\n curl --request PATCH \\\n --header \"Authorization: Bearer \"$(gcloud auth print-access-token) \\\n --header 'Accept: application/json' \\\n --header 'Content-Type: application/json' \\\n --data '{\"type\":\"FIRESTORE_NATIVE\"}' \\\n \"https://firestore.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/databases/\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e?updateMask=type\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project ID\n- \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: the database ID\n\nChange database to **Datastore mode**: \n\n### gcloud\n\nUse the [gcloud firestore databases update](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/update) command to change your database to Datastore mode. \n\n gcloud firestore databases update --type=datastore-mode --database='\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e'\n\nReplace \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e with the ID of your database.\n\n### rest\n\n curl --request PATCH \\\n --header \"Authorization: Bearer \"$(gcloud auth print-access-token) \\\n --header 'Accept: application/json' \\\n --header 'Content-Type: application/json' \\\n --data '{\"type\":\"DATASTORE_MODE\"}' \\\n \"https://firestore.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/databases/\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e?updateMask=type\"\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project ID\n- \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: the database ID"]]