Namespace: firestore Stay organized with collections Save and categorize content based on your preferences.
rules. firestore
Context specific variables and methods for Cloud Firestore security rules.
Functions in this namespace are only available insideservice cloud.firestore { ... } blocks and do not need to be prefixed when used (get() notfirestore.get()).
Interfaces
Request
The incoming request context for a Firestore operation.
Resource
The Firestore document being read or written.
Properties
request
non-nullrules.firestore.Request
The request context, including authentication information and pending data.
resource
non-nullrules.firestore.Resource
The resource being read or written.
Methods
exists
exists(path) returns rules.Boolean
Check if a document exists.
Parameter | |
|---|---|
path | The path. Value must not be null. |
- Returns
non-nullrules.Booleantrue if the resource exists.
Example
// Check if another document existsallowwrite:ifexists(/databases/$(database)/documents/things/other)existsAfter
existsAfter(path) returns rules.Boolean
Check if a document exists, assuming the current request succeeds. Equivalent to getAfter(path) != null.
Parameter | |
|---|---|
path | The path. Value must not be null. |
- Returns
non-nullrules.Booleantrue if the resource exists.
get
get(path) returns rules.firestore.Resource
Get the contents of a firestore document.
Parameter | |
|---|---|
path | The path. Value must not be null. |
- Returns
non-nullrules.firestore.Resourcethe document, or null if it does not exist.
Example
// Get the 'thing1' document from the 'things' collectionget(/databases/$(database)/documents/things/thing1)getAfter
getAfter(path) returns rules.firestore.Resource
Get the projected contents of a document. The document is returned as if the current request had succeeded. Useful for validating documents that are part of a batched write or transaction.
Parameter | |
|---|---|
path | The path. Value must not be null. |
- Returns
non-nullrules.firestore.Resourcethe document, or null if it does not exist.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2019-12-13 UTC.