OrientDB 在连接到一个顶点时遍历(children)并得到另一个顶点
OrientDB traverse (children) while connected to a vertex and get an other vertex
我不确定标题是否是表达它的最佳方式,结构如下:
Structure
这里是数据库 json 备份,如果你想导入它来测试它:http://pastebin.com/iw2d3uuy
我想要在 _Parent Human 移居到 Continent 2 之前让生活在 Continent 1 的人类吃掉的菜肴。
这意味着目标是第 1 道菜和第 2 道菜。
如果一个parent搬到另一个大陆,我不要他们的菜,也不要他们children的菜,即使他们搬回大陆1。
我不知道这是否重要,但一个人可以有多个 children.
如果没有关于 children of a Human who has moved from the Continent 的条件,此查询将有效:
SELECT expand(in('_Is_in').in('_Lives').in('_Eaten_by'))
FROM Continent WHERE continent_id = 1
但我想在这里我们被迫使用(除其他外)
TRAVERSE out('_Parent') FROM Human WHILE
在尝试获取 Dishes 之前,我尝试使用带有子查询的 while 遍历来获取我感兴趣的所有 Humans,但我什至不确定我们是否可以使用 while with a子查询。
我希望该结构能帮助其他用户快速了解此查询是否对他们有用。如果有人想知道,我使用 OrientDB Studio 的图形选项卡和 GIMP 来制作它。
作为奖励,如果有人知道 Gremlin 语法,学习它也会很有用。
请随时编辑此 post 您认为合适的内容并贡献您的想法:)
SELECT expand(in('_Eaten_by'))
FROM (TRAVERSE out('_Parent')
FROM (SELECT from Human WHERE in('_Parent').size() = 0)
WHILE out('_Lives').out('_Is_in').continent_id = 1)
解释:
TRAVERSE out('_Parent')
FROM (SELECT FROM Human WHERE in('_Parent').size() = 0)
WHILE out('_Lives').out('_Is_in').continent_id = 1
returns 人类 1 和 2。
该查询遍历人类,从人类 1 开始,人类连接到大陆 1。
它从 in('_Parent').size() = 0
开始,它们是没有任何 _Parent 的人类(在这种情况下只有人类 1)(size() 是来自 _Parent 的顶点集合的大小)。
- 和
SELECT expand(in('_Eaten_by')) FROM
获取 Dishes,从我们通过遍历得到的 Humans 开始,经过边 _Eaten_by。
注意:一定要始终在顶点和边名称周围使用 ',否则这些名称似乎没有被考虑在内。
我不确定标题是否是表达它的最佳方式,结构如下:
Structure
这里是数据库 json 备份,如果你想导入它来测试它:http://pastebin.com/iw2d3uuy
我想要在 _Parent Human 移居到 Continent 2 之前让生活在 Continent 1 的人类吃掉的菜肴。 这意味着目标是第 1 道菜和第 2 道菜。
如果一个parent搬到另一个大陆,我不要他们的菜,也不要他们children的菜,即使他们搬回大陆1。 我不知道这是否重要,但一个人可以有多个 children.
如果没有关于 children of a Human who has moved from the Continent 的条件,此查询将有效:
SELECT expand(in('_Is_in').in('_Lives').in('_Eaten_by'))
FROM Continent WHERE continent_id = 1
但我想在这里我们被迫使用(除其他外)
TRAVERSE out('_Parent') FROM Human WHILE
在尝试获取 Dishes 之前,我尝试使用带有子查询的 while 遍历来获取我感兴趣的所有 Humans,但我什至不确定我们是否可以使用 while with a子查询。
我希望该结构能帮助其他用户快速了解此查询是否对他们有用。如果有人想知道,我使用 OrientDB Studio 的图形选项卡和 GIMP 来制作它。
作为奖励,如果有人知道 Gremlin 语法,学习它也会很有用。
请随时编辑此 post 您认为合适的内容并贡献您的想法:)
SELECT expand(in('_Eaten_by'))
FROM (TRAVERSE out('_Parent')
FROM (SELECT from Human WHERE in('_Parent').size() = 0)
WHILE out('_Lives').out('_Is_in').continent_id = 1)
解释:
TRAVERSE out('_Parent') FROM (SELECT FROM Human WHERE in('_Parent').size() = 0) WHILE out('_Lives').out('_Is_in').continent_id = 1
returns 人类 1 和 2。
该查询遍历人类,从人类 1 开始,人类连接到大陆 1。
它从 in('_Parent').size() = 0
开始,它们是没有任何 _Parent 的人类(在这种情况下只有人类 1)(size() 是来自 _Parent 的顶点集合的大小)。
- 和
SELECT expand(in('_Eaten_by')) FROM
获取 Dishes,从我们通过遍历得到的 Humans 开始,经过边 _Eaten_by。
注意:一定要始终在顶点和边名称周围使用 ',否则这些名称似乎没有被考虑在内。