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.single()
Create a Set containing a single provided element.
Description
Creates a Set containing a single element. The element is passed to the method as an argument.
You can use an event source to track changes to a Set containing a single document. These event sources only emit events when the document changes.
You typically use Set.single()
to create a Set from a Document
for a document event source.
Examples
The following uses single()
to creates a Set from a single document.
// Uses the `Product` collection's `byName()` index and
// the `first()` method to get a single document.
let product = Product.byName("cups").first()
Set.single(product)
{
data: [
{
id: "111",
coll: Product,
ts: Time("2099-03-21T19:40:45.430Z"),
name: "cups",
description: "Translucent 9 Oz, 100 ct",
price: 698,
stock: 100,
category: Category("123")
}
]
}
You can call set.eventsOn()
or
set.eventSource()
on the Set
to create a document event sources.
let product = Product.byName("cups").first()
Set.single(product).eventSource()
The query returns an event source:
"g9WD1YPG..."
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!