0

So my firestore database is structured as such:

documents -> collection -> docID -> collections -> documents

Inside the docID document I have a field called live which is a boolean set to either true or false. If live is true, I want to allow access to all documents and subdocuments, but if its false do not allow read. I've tried structuring it as such:

match /collections/{docID} {
    allow read: if resource.data.live == true;
    allow write: if false;
}

What is incorrect with this code?

1
  • Could you please share a screenshot of your database in which one of the identities you mention is displayed? This will allow us to have a better undestanding of your database's structure Commented Jul 21, 2020 at 13:44

1 Answer 1

1
match /collection/{docID} {

  match /collections/{document=**} {
       allow read: if get(/databases/$(database)/documents/collection/$(docID)).data.live == true;
       allow write: if false;
  }

}

Here, document=** means all nested documents (of the same collection as well as nested). And a simple get call to read your {docID} document.

You can find more info here Access other documents

Sign up to request clarification or add additional context in comments.

1 Comment

would you care to clarify this answer? does it mean only IDs with that condition under the ID will be allowed? I have a similar situation where I have a users collection and a conversations one. I only want to allow users access to their own data except when they are part of a conversation - needed because user A posts an update to user B conversations information in current code base. If anyone can provide more clarity and details that is greatly appreciated, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.