Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Fauna delete first item from intersection

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 the ref field in the values definition.

Once you use Intersection, Union, or Difference, the resulting set only includes the fields defined in an index's values definition: the implicit ref field is lost.

In Fauna, sets are unbounded, so there aren't any concrete items to operate on until the set is materialized via Paginate or Get. 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 Paginate only 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 Intersection result includes the document reference to delete, or you won't be able to delete.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!