Variables
These variables are available in every rule expression.data and newData are scoped to the current path where the rule is defined. Use root when you need to look up data elsewhere in your database.Snapshot methods
Thedata, newData, and root variables are all snapshots. You can call these methods on any snapshot.
Examples
String methods
These methods are available on any string value in a rule expression, includingauth.uid, $wildcard captures, and string values returned by val().
Examples
Operators
Standard operators work inside rule expressions.Comparison
== is treated as === and != is treated as !== in rules. Both are strict comparisons; there is no loose equality.Logical
Arithmetic
Ternary
Query-based rules
You can restrict what queries clients are allowed to run by referencingquery. expressions in your rules. This lets you enforce that clients include certain filters or limits.
Query variables
Examples
Restrict access to a collection so clients can only read their own items:What’s next
Rules examples
See these building blocks in action with real-world patterns.
Security rules
Go back to the overview to understand how rules are structured and evaluated.

