Y. Chen
Y. Chen

Reputation: 135

Firestore security rules passing wildcard variable to path

I have the following security rules:

    match /collection1/{doc_id} {
      allow read: if (get(/databases/$(database)/documents/collection2/$(doc_id)).author == 
                  request.auth.uid);
    }

What I am doing is that I am trying to pass the wildcard variable from the parent path doc_id into the path of get method. The read access of this doc in collection1 depends on the author field of a document with the same id in another collection collection2. I don't believe that the way I am passing doc_id as $(doc_id) is correct, as I get an error of: Property author is undefined on object

I have also tried (doc_id) and \doc_id, but they are syntaxilly wrong. How do I pass a wildcard variable to a path then?

Upvotes: 0

Views: 216

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

You're missing a data in there, which is needed to get at the fields of the document:

get(/databases/$(database)/documents/collection2/$(doc_id)).data.author

Upvotes: 1

Related Questions