Reputation: 31
I want to set the rules like this: When user's uid is contained in an array field in the city document, that user has authority.
I made it like this. Please tell me how to do it
allow read : if (city.some-array.contain(uid));
service cloud.firestore {
match /databases/{database}/documents {
// Match any document in the 'cities' collection
match /cities/{city} {
allow read: ***if <condition>;***
allow write: if <condition>;
}
}
}
Upvotes: 1
Views: 2824
Reputation: 1477
You can use resource.data
, an object containing the current data before the operation, combined with in
to achieve this.
match /cities/{city} {
allow read, write: if request.auth.uid in resource.data.authorizedUsers
// replace authorizedUsers with the name of your array field
}
Upvotes: 5