I have an app using Cloud Firestore. I'm trying to secure my database with Firebase security rules and have been struggling with receiving a document that I'm querying through a collection group query.
- Here is my security rule that is passing the emulator, but not inside my web app.
match /{path=**}/groups/{groupId} {
allow read: if resource.data.id == resource.id;
}
- If I hardcode my rule to this:
match /{path=**}/groups/{groupId} {
allow read: if resource.data.id == "1" <--- hard coding the value to match my DB, this works;
}
- This is how I query for the group:
this.db
.collectionGroup('groups')
.where('id', '==', id)
.get()
.then(snapshot => { ... });

1, which contains an id field1. May be redundant. I believe what is happening with your hardcore rule is expected since the only instance, which this rule will work is only when the value is "1". If your document2had anidfield, which equals2, then it will only work for hardcoded value2and not1, and so forth. Hope this helps. - sllopis