2

我已将数据存储在 ArangoDB 2.7.1 中,与集合名称 DSP 一样:

{"content": "Book.xml", "type": "string", "name": "name", "key": 102}
{"content": "D:/XMLexample/Book.xml", "type": "string", "name": "location", "key": 102}
{"content": "xml", "type": "string", "name": "mime-type", "key": 102}
{"content": 4130, "type": "string", "name": "size", "key": 102}
{"content": "Sun Aug 25 07:53:32 2013", "type": "string", "name": "created_date", "key": 102}
{"content": "Wed Jan 23 09:14:07 2013", "type": "string", "name": "modified_date", "key": 102}
{"content": "catalog", "type": "tag", "name": "root", "key": 102}
{"content": "book", "type": "string", "name": "tag", "key": 103} 
{"content": "bk101", "type": {"py/type": "__builtin__.str"}, "name": "id", "key": 103}
{"content": "Gambardella, Matthew", "type": {"py/type": "__builtin__.str"}, "name": "author", "key": 1031} 
{"content": "XML Developer's Guide", "type": {"py/type": "__builtin__.str"}, "name": "title", "key": 1031}
{"content": "Computer", "type": {"py/type": "__builtin__.str"}, "name": "genre", "key": 1031}
{"content": "44.95", "type": {"py/type": "__builtin__.str"}, "name": "price", "key": 1031}
{"content": "2000-10-01", "type": {"py/type": "__builtin__.str"}, "name": "publish_date", "key": 1031}
{"content": "An in-depth look at creating applications with XML.", "type": {"py/type": "__builtin__.str"}, "name": "description", "key": 1031}

在这里,单个集合{"content": "Book.xml", "type": "string", "name": "name", "key": 102}表示集合中的单个文档。

现在,我想访问key多个文档中具有相似属性值的所有文档,或者类型为计算机的值标题和价格”以获得相同的key值。我尝试了 AQL asFOR p IN DSP filter p.name == "publish_date" AND p.content == "2000-10-01" AND p.name == 'title' return p但这返回一个空集,因为它是在单个文档中比较,而不是在集合中。

像关系数据库一样,需要某种自联接,但我不知道如何应用自联接。请告诉我如何访问具有相同键属性值的所有文档,其中publish_date“2000-10-01”。我希望此查询的结果是以下文档,因为对应于publish_date值为 2000-10-01 的值为key1031:

{"content": "Gambardella, Matthew", "type": {"py/type": "__builtin__.str"}, "name": "author", "key": 1031} 
{"content": "XML Developer's Guide", "type": {"py/type": "__builtin__.str"}, "name": "title", "key": 1031}
{"content": "Computer", "type": {"py/type": "__builtin__.str"}, "name": "genre", "key": 1031}
{"content": "44.95", "type": {"py/type": "__builtin__.str"}, "name": "price", "key": 1031}
{"content": "2000-10-01", "type": {"py/type": "__builtin__.str"}, "name": "publish_date", "key": 1031}
{"content": "An in-depth look at creating applications with XML.", "type": {"py/type": "__builtin__.str"}, "name": "description", "key": 1031}
4

1 回答 1

3

假设发布日期存储在属性中name,其值存储在属性中content,您首先需要找到具有该组合的所有文档:

FOR self IN DSP 
  FILTER self.name == 'publish_date' && self.content == '2000-10-01'
  RETURN self

现在,找到这些文档后,您可以再次将它们加入 DSP 集合,过滤掉具有相同key值的文档,但从初始值中排除已找到的文档FOR

FOR self IN DSP 
  FILTER self.name == 'publish_date' && self.content == '2000-10-01'
  FOR other IN DSP 
    FILTER other.key == self.key && other._key != self._key 
    RETURN { self, other }

如果您总是根据名称和内容和/或键进行过滤,那么将这些属性编入索引可能是明智的。它看起来key值得自己建立一个索引。哈希索引应该足够了,因为key它将始终进行相等比较。namecontent(按此顺序)可以放入跳过列表索引。

于 2016-01-20T08:25:27.430 回答