ArangoDB查询中嵌入列表的属性

3
我有一个嵌套在列表中的文档,我需要查询与一系列字符串值匹配的文档。
我的文档:
如您所见,我有一个常规文档。在该文档内部是“categories”,每个文档的长度未知。在类别中,我有“confidence”和“title”。我需要查询以查找具有与我在ArrayList中拥有的标题列表匹配的标题的文档。我认为有效的查询是:
FOR document IN documents FILTER document.categories.title IN @categories RETURN article @categories是一个包含标题列表的ArrayList。如果任何标题在ArrayList中,则应将其返回。
此查询似乎返回null。我不认为它会比较ArrayList与我的文档中的“title”字段。我知道可以使用[#]访问“categories”列表,但我不知道如何搜索“categories”中的“title”。
1个回答

3

查询

FOR document IN documents 
  FILTER document.categories.title IN @categories 
  RETURN article

如果document.categories是一个标量值,那么这将起作用,但如果document.categories是一个数组,则不起作用。原因是左侧IN运算符处的数组不会自动扩展。
为了找到文档,查询可以重写如下:
FOR document IN documents 
  FILTER document.categories[*].title IN @categories 
  RETURN document

或者

FOR document IN documents 
  LET titles = (
    FOR category IN document.categories
      RETURN category.title
  )
  FILTER titles IN @categories 
  RETURN document

除此之外,如果没有名为article的集合,则article将是未知的。它应该改成documentdocument.article更合适。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接