You can use the Google Cloud CLI to test your application locally and to manage indexes for your production Firestore in Datastore mode instance. This page describes the typical workflow for these activities.
The gcloud CLI supports the following workflow:
- Create local support for a Datastore instance, including directory, required files, and project ID.
- Start up the Datastore emulator, which provides local emulation of the production Datastore environment.
- Generate index definitions from your application's queries to the emulator.
- Upload manually created or generated index definitions to your production database instance.
- Delete unused indexes from your production database instance.
The development workflow using the command-line tool
The following is the typical workflow using the gcloud CLI:
Set environment variables so your application knows it is using the emulator.
Start your application and test it against the emulator. You need to run the queries your application uses against the emulator in order to generate indexes for your production database instance.
Upload the generated indexes with the
indexes createcommand, passing in the path to your local
index.yamlfile, as in the following example:
gcloud datastore indexes create ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
The example path assumes you have not set a specific directory for the
data-diroption. If you have set a specific directory, modify the path to use the path to your
Remove environment variables so your application knows it is using the production database instance.
Run your application against your production database instance.
Over time, you might no longer use some of the indexes. You can delete unused indexes from your production database instance by removing them from your local
index.yamlfile and then invoking the
gcloud datastore indexes cleanup ~/.config/gcloud/emulators/datastore/WEB-INF/index.yaml
If you have set a specific directory for the
data-diroption, modify the path in the example to use the path to your