What if I call Abort in the lambda of a index binding?
That would cause the index binding to fail, and prevent the transaction from completing. If that
Abort prevented any updates to the sourced collections, you would need to delete that index and create a replacement that used the correct logic.
Would you confirm that I might, this way, craft an index predicate?
I mean: if index binding lambda fails, the affecting row cannot go into the index…
This is a conceptual workaround while I wait for a reply to my more specific request about index predicates support in Fauna…
You can certainly call
Abort in an index predicate. We document the list of functions that cannot be used in index bindings here: Indexes | Fauna Documentation
Not to bother:
I have a collection of people, with a gender field whose values are in [m,f].
Now I create an index called JUST_WOMEN with a lambda binding on gender, which calls Abort if gender is ‘m’.
I expect a query on the index with gender === ‘m’ to return no documents.
Is this so?
Are there better ways to build an index and prefiltering on some Terms’ values?
Abort in an index binding fails the transaction. You get a hint that there are index entries where
m because the transaction fails, but you cannot know how many there are or any other details about matching documents.
If the binding is defined in the index’s
terms field , it is not possible to create documents where
m. If the binding is defined in the index’s
values field, all queries that involve the index where
gender is in the
values field would fail with an error whenever an otherwise matching document exists with its
gender field set to
Typically, you would just set the
gender field to
f as documents are created or updated. When you index that field by specifying it in the index’s
terms field, then you can query for
f like so:
Abort is not required (or advised) for searching.
If you have not already done so, I suggest that you take a look at the index tutorial on searching: Search with indexes | Fauna Documentation
If you still have questions after that, I’d certainly appreciate knowing what those questions might be: it would help to improve that tutorial.
Thanks for your exhaustive reply.
I conclude that indexing in Fauna is a 1:1 function.