I have a document in Cloud Firestore.
The structure of the "events" field is as follows:
{
"events" : [
"eventID-1": [
"value1",
"value2"
],
"eventID-2": [
"value2",
"value3"
],
"eventID-3": [
"value3",
"value4"
]
]
}
Updating [swift]:
self.db.collection("collection").document(document).updateData([
"events.eventID-1": FieldValue.arrayUnion([value2])
...
How do I make up Firebase Cloud Firestore Security Rules:
value were unique. That is, when writing, check if the value does not exist in arrays eventID-1, eventID-2, eventID-3 ....
Check (length) the value that comes for recording
I just figured out how to check the incoming data, that it's a map and that we only get one value.
match /databases/{database}/documents {
match /collection/{documentID} {
allow write: if request.resource.data is map
&& request.writeFields.size() == 1
}
}
UPD : It's been dealt with:
- Checking the string length in the query
allow write : if request.resource.data.events.values()[0].size() < 100
- Checking uniqueness in the list
allow write : if (request.resource.data.events.keys()[0] in resource.data.events.keys()) == false
But I have not figured out how to solve my problems (((( Help!!!