列表中嵌入的ArangoDB查询属性

时间:2015-01-10 23:53:26

标签: graph-databases arangodb aql nosql

我在列表中嵌入了一个文档,我需要查询与一系列字符串的值匹配的文档。

我的文件:

enter image description here

如您所见,我有一份常规文件。在该文件中是"类别"每个文档的长度未知。在内部类别中我有"信心"和"标题"。我需要查询以查找具有与ArrayList中的标题列表匹配的标题的文档。我认为可行的查询是:

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

@categories是一个带有标题列表的ArrayList。如果ArrayList中的任何标题都在文档中,我希望它被返回。

此查询似乎正在返回null。我不认为它正在降低到将ArrayList与"标题"进行比较的程度。我的文件中的字段。我知道我可以访问"类别"使用[#]列表,但我不知道如何在"类别中搜索"标题"。

1 个答案:

答案 0 :(得分: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