I have a fauna db query that will return one match due to the combination of fields being unique:
await faunaClient.query(
Intersection(
Match(Index('tokens_search_by_blacklisted'), false),
Match(Index('tokens_search_by_token'), refreshToken),
Match(Index('tokens_search_by_type'), tokenTypes.REFRESH)
)
)
What I want to know is from here how can I delete the first item returned, I know theoretically I can paginate, lambda delete but I don't want to iterate. I would just like to delete the first value returned.
I know if you use Get it will get the first item from a set but sadly delete doesn't do this and I shouldn't have to get the object aka perform a read just to select the ref then delete.
When you use
Match, the result is a set reference for an index-backed set. Such sets include a reference to the covered document, even if the index doesn't explicitly specify thereffield in thevaluesdefinition.Once you use
Intersection,Union, orDifference, the resulting set only includes the fields defined in an index'svaluesdefinition: the implicitreffield is lost.In Fauna, sets are unbounded, so there aren't any concrete items to operate on until the set is materialized via
PaginateorGet. So, you'll need to use one of those functions in order to retrieve the tuples from the intersection.You can set the page size to 1 so that
Paginateonly returns one item.Paginate's implementation returns as soon as it has a page full of results, so it performs pretty well.You'll need to be sure that the tuples in the
Intersectionresult includes the document reference to delete, or you won't be able to delete.