Manage databases | Firestore | Firebase
Manage databases
Stay organized with collections. Save and categorize content based on your preferences.
Required roles and permissions
To create and manage databases, you'll need the following Identity and Access Management role:
- Cloud Datastore Owner (
roles/datastore.owner)
That role grants the following permissions that you need to create and manage databases:
- Create a database:
datastore.databases.create - Read database configuration:
datastore.databases.getMetadata - Configure a database:
datastore.databases.update - Delete a database:
datastore.databases.delete - Clone a database:
datastore.databases.clone
Create a database
To create a database, use one of the following methods:
ConsolegcloudFirebase CLITerraform
Firebase console
- In the Firebase console, go to Databases & Storage > Firestore.
Go to Firestore - Click Add database.
- Select Standard edition. Click Next.
- Enter a Database ID.
- Select a location for your database. Click Next.
- Select a starting mode for your Cloud Firestore Security Rules:
- Test mode: Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, make sure to review the Secure your data section.
- Production mode: Denies all reads and writes from mobile and web clients. Your authenticated application servers (Node.js, Python, Java) can still access your database.
- Click Create.
Using gcloud command
Use the gcloud firestore databases create command.
gcloud firestore databases create \
--database=DATABASE_ID \
--location=LOCATION \
--edition=standard \
--type=DATABASE_TYPE
Replace the following:
- DATABASE_ID: a valid database ID.
- LOCATION: the name of a Cloud Firestore multi-region or region.
- DATABASE_TYPE: either
firestore-nativefor Native mode ordatastore-modefor Datastore mode.
--delete-protection is an optional flag to enable deletion protection.
Tags
To add tags to the database, use the --tags flag:
--tags=123/environment=production,123/costCenter=marketing
Update database configuration
To update the configurations settings of a database, use the gcloud firestore databases update command.
Delete a database
To delete a database, use the console or command-line tool.
- In the Firebase console, go to Databases & Storage > Firestore.
- In the Data tab, above the data table view for the database, click more_vert, then select Delete database.
- Follow the instructions to delete the database.
Use the gcloud firestore databases delete command.
gcloud firestore databases delete --database=DATABASE_ID
Replace DATABASE_ID with the ID of the database to delete. To delete the default database use the ID '(default)'.
Clone a database
You can clone an existing database at a selected timestamp into a new database:
- The cloned database is a new database that will be created in the same location as the source database.
- To make a clone, Cloud Firestore uses point-in-time recovery (PITR) data of the source database. The cloned database includes all data and indexes.
Use the gcloud firestore databases clone command to clone a database:
gcloud firestore databases clone \
--source-database='SOURCE_DATABASE' \
--snapshot-time='PITR_TIMESTAMP' \
--destination-database='DESTINATION_DATABASE_ID'
Replace the following:
- SOURCE_DATABASE: the database name of an existing database that you want to clone.
- PITR_TIMESTAMP: a PITR timestamp in the RFC 3339 format.
- DESTINATION_DATABASE_ID: a database ID for a new cloned database.
IAM Conditions
You can use Identity and Access Management Conditions to configure access permissions on a per-database level. The following examples use the Google Cloud CLI to assign conditional access.
Cloud Monitoring
Cloud Firestore metrics are reported under two monitored resources:
Limitations
- You can have a maximum of 100 databases per project. You can contact support to request an increase to this limit.
- You cannot delete your
(default)database if it contains any GAE search data.