eventSource.where()
Learn: Event Feeds and Event Streams |
---|
Create an event source that emits events for a subset of another event source’s tracked Set.
Description
The where()
method returns an event source. The
event source emits events for a subset of
another event source’s tracked Set.
The subset’s elements must match a provided predicate function. The predicate must return a Boolean or Null.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
predicate |
Yes |
Anonymous predicate function
that’s compared to an existing event source's
Set elements. The function returns |
Return value
Type | Description |
---|---|
String-encoded token for an event source. The event source emits events for Set elements that match the provided predicate function. |
Examples
// Only emit events for `Customer` documents
// with an `.address.state` of `DC`.
Customer.all()
.eventSource()
.where(.address.state == "DC")
// String-encoded token for the new event source
"g9WD1YPG..."
When consumed as an Event Feed or Event Stream, the event source emits events for the subset matching the provided predicate function:
// The new event source only emits events
// for `Customer` documents with an
// an `.address.state` of `DC`.
{
"type": "update",
"data": {
"@doc": {
"id": "111",
"coll": {
"@mod": "Customer"
},
"ts": {
"@time": "2099-10-30T20:18:18.390Z"
},
"cart": {
"@ref": {
"id": "413111684333305922",
"coll": {
"@mod": "Order"
}
}
},
"orders": {
"@set": "hdW..."
},
"name": "Alice Appleseed",
"email": "alice.appleseed@example.com",
"address": {
"street": "87857 Mendota Court",
"city": "Washington",
"state": "DC",
"postalCode": "20220",
"country": "US"
}
}
},
"txn_ts": 1730319498390000,
"cursor": "gsG...",
"stats": {
"read_ops": 3,
"storage_bytes_read": 1049,
"compute_ops": 1,
"processing_time_ms": 50,
"rate_limits_hit": []
}
}
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!