Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now in beta. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. |
set.changesOn()
|
Create an event source that tracks changes to specified document fields in a supported Set.
Description
Creates an event source token that tracks changes to specified document fields in a Set. The token has the EventSource type:
"g9WD1YPG..."
You can only call changesOn()
on a
supported Set. The exact
behavior of the method depends on this source. The calling Set isn’t
changed.
Sets for event sources support a limited number of transformations and filters.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
fields |
Yes |
Comma-separated list of document field accessors (using dot notation). The event source tracks changes to the values of these document field. |
Return value
Type | Description |
---|---|
A string-encoded token that represents the event source. Use the token to consume events as an Event Feed or Event Stream. |
Examples
Collection event sources
You can use changesOn()
to only track changes to specific fields
for documents in a collection.
Product.all().changesOn(.description)
The query returns an event source.
"g9WD1YPG..."
Index event sources
Event sources for 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
terms
field ofname
-
values
fields ofname
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 event sources
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("111")!
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!