英文:
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}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论