【问题标题】:how to fetch data from one class to another in orientdb如何在orientdb中将数据从一个类获取到另一个类
【发布时间】:2016-05-19 10:47:37
【问题描述】:

我创建了两个类 customercitycustomer 类包含 namelocation 两个属性,city 类包含 id 和 位置。 我想对这两个类执行连接操作。 我在 orientdb studio 中创建了一个图形关系并在下面触发了一个查询

select from customer where city.location='pune'

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

【问题讨论】:

  • “位置”字段的类型是什么?
  • “客户”类没有“城市”字段,您已声明“名称”和“位置”字段
  • 嗨,您能发布完整的架构,包括顶点类和边类吗?
  • 字段位置的类型是字符串。
  • 嗨,Ivan,这是完整的架构...我已经采用了两个顶点客户和城市。在客户类中,有两个属性名称和城市,在城市中有两个属性 id 和位置............并且我创建了边 LivesAt。我展示了像'suresh LivesAt pune'这样的图形关系......

标签: database mongoose orientdb graph-databases


【解决方案1】:

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

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]
----+-----+--------+----+-----------

希望对你有帮助

【讨论】:

  • 嗨,suresh,很高兴能提供帮助。如果您认为这是正确的答案,您可以将其标记为正确答案吗?
猜你喜欢
  • 1970-01-01
  • 2016-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-15
  • 1970-01-01
  • 2020-09-26
相关资源
最近更新 更多