I have a firestore database with a collection of products and a collection of categories.
I want give at the user the delete permission on the categories collection only if the category document not have a products
field.
the products field is an array of reference.
I have this rules:
match /shops/{shopId} {
allow read: if true;
allow write: if false;
match /categories/{category=**}{
allow read: if true;
allow write: if resource.data.products == null;
}
}
But this rules not works, I cannot write or update a document.
Open the Firebase console and select your project. Then, from the product navigation, do one of the following: Select Realtime Database, Cloud Firestore, or Storage, as appropriate, then click Rules to navigate to the Rules editor.
Collections and documents are created implicitly in Cloud Firestore. Simply assign data to a document within a collection. If either the collection or document does not exist, Cloud Firestore creates it.
Try this
match /shops/{shopId} {
allow read: if true;
allow write: if false;
match /categories/{category=**}{
allow read: if true;
allow create: if true;
allow update, delete: if !('products' in resource.data);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With