如何使用ArangoDB中的自连接访问集合中多个文档中的数据
我已将数据以集合名DSP的形式存储在ArangoDB 2.7.1中:如何使用ArangoDB中的自连接访问集合中多个文档中的数据,arangodb,aql,Arangodb,Aql,我已将数据以集合名DSP的形式存储在ArangoDB 2.7.1中: {"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",
{"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
值,在类型为computer的情况下,访问具有类似值title和price的所有文档。我已经在DSP filter p p中尝试了一个AQL作为用于p。name==“publish_date”和p.content==“2000-10-01和p.name=='title'返回p
,但这返回的是一个空集,因为它在单个文档中进行比较,而不是在集合中进行比较
像关系数据库一样,需要某种类型的自连接,但我不知道如何应用自连接。请告诉我如何访问键属性值相同的所有文档,其中publish\u date
为“2000-10-01”。我希望此查询的结果出现在以下文档中,因为对应于值为2000-10-01的publish\u date
,key
的值为1031:
{"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}
假设发布日期存储在属性
name
中,其值存储在属性content
中,则首先需要查找具有该组合的所有文档:
FOR self IN DSP
FILTER self.name == 'publish_date' && self.content == '2000-10-01'
RETURN self
现在,找到这些文档后,您可以再次将它们加入DSP集合,筛选出具有相同键
值的文档,但从的初始中排除已找到的文档:
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 }
如果您总是根据名称、内容和/或键进行筛选,那么为这些属性编制索引可能是明智的。看起来键
本身就应该有一个索引。散列索引应该足够了,因为键
总是相等的<代码>名称
和内容(按此顺序)可以放入skiplist索引中