-
Notifications
You must be signed in to change notification settings - Fork 64
using firestore in datastore mode
Cloud Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. It is the newest version of Cloud Datastore and introduces several improvements over Datastore.
Because Cloud Datastore is optimized for server use cases and for App Engine, we recommend using Datastore mode for databases that will be used primarily by App Engine apps. Cloud Firestore in Native mode is most useful for mobile and real-time notification use cases. For more information about Firestore modes, see Choosing between Native Mode and Datastore mode.
To use Datastore mode with App Engine:
- If you haven't already done so, create a database and choose Cloud Firestore in Datastore mode.
You can use existing Cloud Datastore databases with App Engine apps. These existing databases will be automatically upgraded to Cloud Firestore in Datastore mode.
-
In your app, declare Cloud Datastore as a dependency by using the
go get cloud.google.com/go/datastorecommand. Alternatively, you can declare dependencies in your app'sgo.modfile. Learn more about specifying dependencies. -
Use the Google Cloud Client Library to read and write entities and to query data.
-
In your app, declare Cloud Datastore as a dependency by adding the library to your app's dependencies file.
-
Use the Google Cloud Client Library to read and write entities and to query data.
-
In your app, declare Cloud Datastore as a dependency by adding
@google-cloud/datastoreto your app'spackage.jsonfile. Learn more about specifying dependencies. -
Use the Google Cloud Client Library to read and write entities and to query data.
-
In your app, declare Cloud Datastore as a dependency by adding
google/cloud-datastoreto your app'scomposer.jsonfile and runningcomposer installfrom your app's directory. Learn more about specifying dependencies. -
Use the Google Cloud Client Library to read and write entities and to query data.
-
In your app, declare Cloud Datastore as a dependency by adding
google-cloud-datastoreto your app'sGemfile. Learn more about specifying dependencies. -
Use the Google Cloud Client Library to read and write entities and to query data.
-
If you have a new Python 3 apps, you should use the Datastore mode client library to interact with Datastore mode:
-
In your app, declare Cloud Datastore as a dependency by adding
google-cloud-datastoreto your app'srequirements.txtfile. Learn more about specifying dependencies. -
Use the Google Cloud Client Library to read and write entities and to query data.
-
If you are planning to upgrade your Python 2 app to Python 3, Google recommends porting your Python 2 app that uses App Engine NDB to Python 3, and then migrating to Cloud NDB. To learn how to access App Engine NDB in Python 3, see the Accessing App Engine legacy bundled services for Python 3.
For additional resources plus an example of migrating from a Python 2 webapp
app using App Engine NDB to an equivalent Python 3 Flask app with App Engine NDB
enabled, see the bundled services for Python
3.
Datastore mode uses indexes for every query your application makes. The indexes are updated whenever an entity changes, so the results can be returned quickly when the app makes a query.
Datastore mode automatically creates single-property indexes for use with simple
types of queries. For complex queries that include multiple properties, you'll
need to configure composite indexes in your app's index.yaml file.
The App Engine development server will update your index.yaml file with the
composite indexes needed to run your tests. Similarly, the Datastore mode
emulator can generate indexes
when you run tests.
You can also add the indexes to your app's index.yaml file
manually if you do not
run local tests or your tests do not include complex queries.
By default, your app has all the permissions required to read and write to Datastore mode and Cloud Firestore databases in your Google Cloud project.
To manage these permissions, each App Engine app uses a default service account that gives full read and write access to Datastore mode and Cloud Firestore databases in the same project as the app. You can change the permissions of the default service account, but your app may lose access unless you assign an IAM role with the required permissions.
For information about allowing other users, apps, or projects to access a database, see Accessing your database.
The gcloud CLI for Java includes a local development 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.
The development server generates configuration for Datastore mode indexes needed by your application, determined from the queries it performs while you are testing it.
The gcloud CLI includes a local emulator of the production Datastore mode mode environment. You can use the emulator to develop and test your application locally. In addition, the emulator can help you generate indexes for your production Datastore mode mode instance and delete unneeded indexes.
If you use the App Engine local development
server
to test your app, you can ensure that the server will use the Datastore mode
emulator by setting the --support_datastore_emulator=true flag when starting
the server.
If you are using the Datastore mode emulator, dev_appserver will display:
... Using Cloud Datastore Emulator.
Datastore mode offers a free quota with daily limits. Paid accounts offer unlimited storage, read, and write operations. More information is available on the Datastore Quotas page.