从交叉口删除第一个项目的动物

发布于 2025-01-29 16:38:42 字数 440 浏览 1 评论 0原文

我有一个Fauna DB查询,该查询将返回一场比赛,因为字段的组合是唯一的:

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)
  )
)

我想知道的是从这里删除我的第一个项目,我知道我可以分页,lambda delete,但我不删除。想迭代。我只想删除返回的第一个值。

我知道,如果您使用它,它将从集合中获取第一项,但可悲的是,删除不执行此操作,我不必让对象aka执行读取只是为了选择ref然后删除。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧街凉风 2025-02-05 16:38:42

当您使用匹配时,结果是索引支持集的集合参考。这样的集合包括对涵盖文档的引用,即使索引未明确指定ref字段中的values定义。

一旦您使用交叉点union差异,结果集仅包括在索引的values中定义的字段定义:隐式ref字段丢失。

在Fauna中,集合是无界的,因此没有任何具体项目可以操作,直到通过paginateget实现该集合为止。因此,您需要使用其中一个功能才能从交叉路口检索元组。

您可以将页面大小设置为1,以便paginate仅返回一个项目。 Paginate的实现一旦有一个充满结果的页面,就会返回,因此其性能非常好。

您需要确保交集中的元素结果包括对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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文