Before creating a database and collection in Cloud Firestore, it prompts you to apply the security rules for our database.
Take a look at the following screenshot:
Here are some code example of Firestore rules:
Public:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
Users:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
}
}
Private:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}