Chapter 08 · Firebase Firestore
Subchapter 8.6
references/enterprise/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 contains database configuration for the
Firebase CLI.firestore.rules: This file contains your security rules.firestore.indexes.json: This file contains your index
definitions.If the user needs to create a new database, ask the user what location to use.
Run npx -y firebase-tools@latest firestore:locations to get the list of
options. Suggest colocating with other resources if applicable.
Use the following command to create a Firestore Enterprise database:
firebase firestore:databases:create my-database-id \
--location="<selected-location>" \
--edition="enterprise" \
--firestore-data-access="ENABLED" \
--mongodb-compatible-data-access="DISABLED"This will create an enterprise database in the selected location with native
mode enabled. A database id is required to create an enterprise database and the
database id must not be (default). To enable realtime-updates feature, use
--realtime-updates flag.
firebase firestore:databases:create my-database-id \
--location="<selected-location>" \
--edition="enterprise" \
--firestore-data-access="ENABLED" \
--mongodb-compatible-data-access="DISABLED" \
--realtime-updates="ENABLED"Create a file named firebase.json in your project root with the following
content (edit database and location to match the ones you created above). If
this file already exists, instead append to the existing JSON:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json",
"edition": "enterprise",
"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.
# To deploy all rules and indexes
firebase deploy --only firestore
# To deploy just rules
firebase deploy --only firestore:rules
# To deploy just indexes
firebase deploy --only firestore:indexesTo run Firestore locally for development and testing:
firebase 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)).