Manage multiple Firestore databases in a project

Google are excited to announce support for multiple Firestore databases in a Google Cloud project. You can now create multiple databases in a project to isolate customer data, microservices, or dev/test/staging environments. 

The multiple databases feature includes support for the following:

Example walkthrough

Sound like a good candidate for your application? Let’s take an end-to-end example to see how it works. 

To create a Firestore database, you need to specify a database identifier, mode, and location. There are multiple ways to create a Firestore database. Here is an example of how to create a Firestore native database named reviews in the us-west1 location using the gcloud CLI:

$ gcloud firestore databases create --database=test --location=us-west1 --type=firestore-native

Once your database is created, you can access it using the Firestore/Datastore console.

When you no longer need a Firestore database, you can delete the Firestore database by running.

$ gcloud alpha firestore databases delete --database=test

That’s everything you need to do. Once a database is deleted, Firestore performs the data deletion on your behalf.

When using the Firestore client libraries with your newly created databases, specify the database name to get the appropriate Firestore database instance. If you don’t specify a database name, the client library falls back to the (default) database. Here’s an example for writing to a database named “test” with the Firebase Admin SDK for Java:

// Initialize Firebase App
FirebaseApp app = FirebaseApp.getInstance();
// Initialize Firestore Database with database id `test`
FirebaseFirestore db = FirebaseFirestore.getInstance(app, “test”)
// Document Reference 
DocumentReference docRef = db.collection(“col”).document(“doc”);
// Write Document
waitFor(docRef.set(Collections.singletonMap(“foo”, “bar”)));

For examples in additional languages, see Accessing your database.

Next steps

For more information on how to set up and configure multiple databases on Firestore, check out the documentation.

Related posts

Looker now available from Google Cloud console

by Cloud Ace Indonesia
1 year ago

Move over 2022: Predictions from Google Cloud experts that will reshape IT

by Cloud Ace Indonesia
2 years ago

Connected Sheets for Looker is now generally available

by Cloud Ace Indonesia
9 months ago