Activate Firestore Database¶
To enable database features in your app using Firebase, you need to activate Cloud Firestore. Follow these steps to set it up properly.
Step 1: Enable the Firestore API¶
- Go to the Google Cloud Firestore API.
- Select your Firebase project from the dropdown at the top.
- Click on the Enable button to activate the Firestore API for your project.
Step 2: Create the Firestore Database¶
- Go to Firebase Console.
- Select your Firebase project.
- Navigate to Build > Firestore Database in the left-hand menu.
- Click Create database.
- Choose the Production mode (recommended for live apps).
- Select the Firestore region closest to your target users.
- Click Enable to complete the setup.
Step 3: Set Firestore security rules¶
After creating the database:
- Open the Rules tab.
- Replace the existing rules with the following:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid} {
allow read, write: if request.auth.uid == uid;
}
}
}
These rules ensure that each authenticated user can only read and write to their own document in the users
collection.
Step 4: First document creation¶
You don’t need to manually create the users
collection.
It will be automatically created after the first successful account creation in your app.
Once this happens, you'll see the users
collection in the Firestore console.