Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Path must be document-level" in firestore rules playground. Why?

I’m learning how to set up the rules for Firestore.

I want to simulate a request of a collection, but it shows an error ("Path must be document-level") and doesn’t let me run the request:

1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why is it so? It is a very common thing to request a collection of documents from their API, so why can I not simulate it in the playground?

Here are the rules I’m testing. They don’t exactly work, but that’s a different question:

rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/todos {
      allow read, write: if request.auth.uid == userId;
    }
  }
}

>Solution :

Even if one can fetch an entire Collection, a match statement in Security Rules must specify a document path, as explained in the doc:

All match statements should point to documents, not collections. A
match statement can point to a specific document, as in match
/cities/SF or use wildcards to point to any document in the specified
path, as in match /cities/{city}.

So, in the simulator, you must specify a document path and therefore check your rule for a specific document.


And don’t forget another important point which is somehow linked to the above: Rules are not filters

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading