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.includes()
Description
Tests if the Set includes a provided element.
Eager loading
This method uses eager loading and requires a read of each document in the calling Set. For large Sets, this may result in poor performance and high costs.
Avoid filtering using includes()
In most cases, you should avoid using set.includes()
to intersect results, including results from
covered index calls.
set.includes()
is a linear operation. The
compute costs consumed by repeatedly
iterating through results will typically exceed the
read costs of directly reading
documents.
For example, the following query is inefficient and will likely incur high compute costs:
// Each variable is a covered index call
let limes = Product.byName("limes")
let produce = Product.byCategory(Category.byName("produce").first()!)
let under5 = Product.sortedByPriceLowToHigh({ to: 500 })
// Uses `includes()` to intersect the results from
// covered index calls
limes.where(doc => produce.includes(doc))
.where(doc => under5.includes(doc))
Instead, use a covered index
call and set.where()
to filter the results as
outlined in Filter using where()
.
For example, you can rewrite the previous query as:
// Start with a covered index call.
Product.byName("limes")
// Layer on filters using `where()`
.where(doc => doc.category == Category.byName("produce").first()!)
.where(doc => doc.price < 500 )
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!