temuri
temuri

Reputation: 2807

Referencing variables in Firestore Rules

Firestore Rules example:

match /cities/{city} {
  allow read: if <condition>;
  allow write: if <condition>;
}

Documentation page says:

The match statement uses the {city} wildcard syntax. This means the rule applies to any document in the cities collection, such as /cities/SF or /cities/NYC. When the allow expressions in the match statement are evaluated, the city variable will resolve to the city document name, such as SF or NYC.

Question:

How to reference that {city} value in actual rules and what is the syntax?

Thanks.

Upvotes: 0

Views: 167

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317402

There's no special syntax - just use city as you would any other variable. It doesn't require any namespacing or identification like $ in some languages.

allow get: if city == "NYC";

Although the above is a silly rule, it's syntactically correct and will prevent any document other than NYC from working with a get() on the client.

Upvotes: 1

Related Questions