Chapter 08 · Firebase Firestore
Subchapter 8.14
references/standard/provisioning.mdMarkdown3 KBView on GitHub
Initialize the following firebase configuration files manually. Do not use
npx -y firebase-tools@latest init, as it expects interactive inputs.
firebase.json: This file configures the Firebase CLI.firestore.rules: This file contains your security rules.firestore.indexes.json: This file contains your index
definitions.Create a file named firebase.json in your project root with the following
content. If this file already exists, instead append to the existing JSON:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
}
}This will use the default database with the Standard edition. To use a different database, specify the database ID and location:
npx -y firebase-tools@latest firestore:locations to get the list of
locations.You can check the list of available databases using
npx -y firebase-tools@latest firestore:databases:list.
If the database does not exist, it will be created when you deploy with the specified configuration:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json",
"database": "my-database-id",
"location": "<selected-location>"
}
}Create a file named firestore.rules. A good starting point (locking down the
database) is:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}See security_rules.md for how to write actual rules.
Create a file named firestore.indexes.json with an empty configuration to
start:
{
"indexes": [],
"fieldOverrides": []
}See indexes.md for how to configure indexes.
CRITICAL: You MUST deploy the firestore configuration for the database to be provisioned in the cloud and for your rules/indexes to take effect. If you don’t run this, your database will not exist.
# To deploy all rules and indexes
npx -y firebase-tools@latest deploy --only firestore
# To deploy just rules
npx -y firebase-tools@latest deploy --only firestore:rules
# To deploy just indexes
npx -y firebase-tools@latest deploy --only firestore:indexesTo run Firestore locally for development and testing:
npx -y firebase-tools@latest emulators:start --only firestoreThis starts the Firestore emulator, typically on port 8080. You can interact with it using the Emulator UI (usually at http://localhost:4000/firestore (opens in a new tab)).