Sulman Azhar
Sulman Azhar

Reputation: 1079

Firestore rules to read documents where specific field exists

In my users collectionI have a few users where a field is present which is called startupData field and now I want to make these documents public. So I am trying to make rules for it but so far no luck.

This is my document with the field.

enter image description here

These are the rules that i have created so far

match /databases/{database}/documents {
match /users/{uid} {
        allow read: if request.auth.uid == uid;
        allow read: if get(/databases/$(database)/documents/users/{document=**}).data.startupData
    }
  }

Upvotes: 0

Views: 529

Answers (1)

remarcoble
remarcoble

Reputation: 683

You probably need to use the hasAll keyword.

match /databases/{database}/documents {
match /users/{uid} {
        allow read: if request.auth.uid == uid;
        allow read: if resource.data.keys().hasAll(['startupData'])
    }
  }

Upvotes: 2

Related Questions