set.changeOn()
Description
You can only call changesOn()
on a Set from a
supported
source. The exact behavior of the method depends on this source. The calling
Set isn’t changed.
Source Sets for streams support a limited number of transformations and filters.
A query that creates a stream returns a stream token.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
fields |
Yes |
Comma-separated list of document field accessors (using dot notation). The stream tracks changes to the values of these document field. |
Examples
Collection streams
You can use changesOn()
to only track changes to specific fields
for documents in a collection.
Product.all().changesOn(.description)
The query returns a stream token.
"g9WD1YPG..."
Index streams
Streams on indexes only send events for changes to the index’s terms or values fields.
For example, the following Product
collection’s byName()
index has:
-
A term field of
name
-
Value fields of
name
andprice
collection Product {
*: Any
index byName {
terms [.name]
values [desc(.stock)]
}
...
}
When called on an index, changesOn()
only accepts the index’s terms or
values fields as arguments.
For example, in the following query, changesOn()
only accepts
.name
and .stock
as arguments.
Product.byName("limes").changesOn(.name, .stock)
Document streams
You can use changesOn()
to track changes to a Set containing a single
document. The following query only tracks changes to the name
or price
field of a single document.
let product = Product.byId(392174614626697728)!
Set.single(product).changesOn(.name, .price)
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!