Query-based rules

As seen in the preceding example, rules can't be used as filters. However, at times, we need to give access to only subsets of data based on some conditions or query parameters. For example, let's say that we need to return only the first 100 records out of 1000 records from the query result set. We can achieve this through the use of the query. expressions to give read and write access to your result set based on the query parameters:

tickets: {
".read": "query.limitToFirst <= 100"
}

The preceding will give access to the first 100 records that are ordered by key by default. If you want to specify orderByChild, you can also do that, as follows:

tickets: {
".read": "query.orderByChild == 'department' && query.limitToFirst <= 100"
}

Ensure that when you read the data, you specify orderByChild, otherwise your read will fail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset