I'm getting "Missing or insufficient permissions" when I have a security rule that checks for a subfield. For example:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /entries/{id} {
allow read: if resource.data.business.id == "hh7AvLpTbFGRmCGodLV4";
}
}
}
The only document I have in entries
collection:
{
"batchId": "bnzVkufp9mM6yGokUYug",
"business": {
"id": "hh7AvLpTbFGRmCGodLV4"
}
}
My query:
firestore()
.collection('entries')
.where('batchId', '==', 'bnzVkufp9mM6yGokUYug')
If I changed the security rule to allow read: if resource.data.batchId == "bnzVkufp9mM6yGokUYug"
, it works fine. Is there something that I missed?
Note:
- The rule works fine when tested using "Rules playground" in Firebase Console, but failed in production.
- I have another project that works fine with rules that check for subfield. However, for 2 new firebase projects that I created, it doesn't work.
- I found a related problem from 2017 (Firestore security rules, nested field). Could this be the same issue re-appearing again?