如何在Arangodb/AQL中选择性地跟踪链接?

huangapple go评论91阅读模式
英文:

How do I follow a link in Arangodb/AQL optionally?

问题

以下是您要翻译的内容:

我现在有一个查询,从一个单一的集合中提取数据:

FOR d IN feed_item
   FILTER d.ingested > @when
   SORT d.score DESC
   LIMIT 50
   RETURN d

我想从另一个集合中提取数据,比如:

FOR d IN feed_item
   FOR j IN INBOUND judgement_of
      FILTER d.ingested > @when
      SORT d.score DESC
      LIMIT 50
      RETURN {d: d, j: j}
但是在judgement_of集合中可能有也可能没有边缘。如果没有边缘,我希望j为null,就像SQL中的LEFT JOIN一样。有没有办法做到这一点?
英文:

I have a query right now that fetches from a single collection

FOR d in feed_item
   FILTER d.ingested>@when
   SORT d.score DESC
   LIMIT 50
   RETURN d

I'd like to fetch data from another collection, say,

FOR d in feed_item
   FOR j IN INBOUND judgement_of
      FILTER d.ingested>@when
      SORT d.score DESC
      LIMIT 50
      RETURN {d:d, j:j}

but there may or may not be an edge in the judgement_of collection. If there is no edge I want j to be null, like the LEFT JOIN in SQL. Is there a way to do this?

答案1

得分: 1

你可以使用子查询来获取可选的数据。类似这样的方式:

   LET j = FIRST(FOR dd IN INBOUND judgement_of d RETURN dd)
   FILTER d.ingested > @when
   SORT d.score DESC
   LIMIT 50
   RETURN {d: d, j: j}
英文:

You can use a subquery to fetch the optional data. Something like this:

FOR d in feed_item
   LET j = FIRST(FOR dd IN INBOUND judgement_of d RETURN dd)
   FILTER d.ingested>@when
   SORT d.score DESC
   LIMIT 50
   RETURN {d:d, j:j}

huangapple
  • 本文由 发表于 2023年2月27日 11:57:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576667.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定