如何查询具有某些属性的邻居顶点?

时间:2015-04-10 10:01:34

标签: sql graph orientdb

我正在使用OrientDB 2.0。查询很简单,但我似乎无法弄明白。我有两个课程:UserUserGroup。为简化起见,User只有usernamepassword属性,而UserGroup只有一个id属性。关系很简单:

User --- user_group --> UserGroup

其中user_group是连接UserUserGroup顶点的边缘类。

我想要做的是让用户拥有某个用户名和密码UserGroup.id等于 group1

到目前为止我所拥有的是:

select expand(in('user_group')[username='foo' and password='bar']) 
from UserGroup
where id = 'group1'

但这对我不起作用。我做错了什么?

3 个答案:

答案 0 :(得分:2)

create class User extends V
create property User.username string
create property User.password string

create class UserGroup extends V
create property UserGroup.id string

create class user_group extends E


create vertex User set username = 'foo', password = 'bar'
create vertex UserGroup set id = 'group1'

create edge user_group from (select from User where username = 'foo') to (select from UserGroup where id = 'group1')


select expand(in('user_group')[username='foo'][password='bar']) 
from UserGroup
where id = 'group1'

答案 1 :(得分:0)

我想,经过几次尝试,我找到了答案:

select from 
   (select expand(in('user_group'))
    from UserGroup
    where id = 'group1')
where username='foo' and password='bar'

如果有人能提出更优雅的解决方案,那也很不错

答案 2 :(得分:0)

select 
from (
     select expand(in('user_group')) 
     from UserGroup 
     where id = 'group1'
) 
where username='foo' and password='bar'