I working in a firebase database. I need to limit the length of a string field. How do I do that?
The path to the field is:
Col1/doc1///description
That is, starting with the collection col1, then into doc1, then for all collections under doc1, and all documents under that collection, the description field needs to be limited to 100 characters.
Can someone please explain to me how to do this? Thanks
I tried to get the validation from the other answer to work but was unsuccessful. Firestore just doesn't like checking .length on resource data values.
I searched around and this article helped me: https://fireship.io/snippets/firestore-rules-recipes/
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /posts/{postId} {
allow read: if true;
allow write: if request.auth != null
&& request.auth.uid == request.resource.data.uid
&& request.resource.data.body.size() > 0
&& request.resource.data.body.size() < 255
&& request.resource.data.title.size() > 0
&& request.resource.data.title.size() < 255;
}
}
}
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