如何在orientdb中从一个类获取数据到另一个类

时间:2016-02-09 12:35:05

标签: database mongoose orientdb graph-databases

我创建了两个类 customer city 客户类包含两个属性 name location city 类包含 id 和< em> location 。 我想对这两个类执行连接操作。 我在orientdb studio中创建了一个图形关系,并在

下面发出一个查询
select from customer where city.location='pune'

但是这个查询没有返回任何值,它执行但没有返回任何字段, 所以,这是正确的语法或我在某处做错了.. 请给我解决方案。

1 个答案:

答案 0 :(得分:2)

我有这个简单的数据集给你一些例子:

create class Customer extends V
create class City extends V
create class livesAt extends E

create property Customer.name String
create property City.id integer
create property City.location String

create vertex Customer set name="Tom"
create vertex Customer set name="John"
create vertex City set id=1, location="London"
create vertex City set id=2, location="Pune"

create edge livesAt from (select from Customer where name="Tom") to (select from City where id=1)
create edge livesAt from (select from Customer where name="John") to (select from City where id=2)

现在,您可以使用不同的查询来检索您正在查找的结果。

查询1a :从客户开始(如上面的查询)

select from Customer where out('livesAt').location in 'Pune'

<强>输出

----+-----+--------+----+-----------
#   |@RID |@CLASS  |name|out_livesAt
----+-----+--------+----+-----------
0   |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------

查询1b :从客户

重新开始
select from Customer where out('livesAt').location contains 'Pune'

<强>输出

----+-----+--------+----+-----------
#   |@RID |@CLASS  |name|out_livesAt
----+-----+--------+----+-----------
0   |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------

查询1c

select from Customer where out('livesAt')[location = 'Pune'].size() > 0

<强>输出

----+-----+--------+----+-----------
#   |@RID |@CLASS  |name|out_livesAt
----+-----+--------+----+-----------
0   |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------

查询2 :从城市开始(更直接

select expand(in('livesAt')) from City where location = 'Pune'

<强>输出

----+-----+--------+----+-----------
#   |@RID |@CLASS  |name|out_livesAt
----+-----+--------+----+-----------
0   |#12:1|Customer|John|[size=1]
----+-----+--------+----+-----------

希望有所帮助