Graph Orientdb用户朋友设计模式

Graph Orientdb用户朋友设计模式,graph,orientdb,nosql,Graph,Orientdb,Nosql,我想在OrientDB中设计用户和朋友关系。 我有1个顶点用户和1个边缘朋友。 这是我在控制台里做的 create class User extends V create class Friend extends E 我从用户0到用户9创建了10个用户 create vertex User set name='User_0' create vertex User set name='User_1' create vertex User set name='User_2' create vert

我想在OrientDB中设计用户和朋友关系。 我有1个顶点用户和1个边缘朋友。 这是我在控制台里做的

create class User extends V
create class Friend extends E
我从用户0到用户9创建了10个用户

create vertex User set name='User_0'
create vertex User set name='User_1'
create vertex User set name='User_2'
create vertex User set name='User_3'
create vertex User set name='User_4'
create vertex User set name='User_5'
create vertex User set name='User_6'
create vertex User set name='User_7'
create vertex User set name='User_8'
create vertex User set name='User_9'
然后我创建了edge Friend

create edge Friend from #11:0 to #11:1
create edge Friend from #11:0 to #11:2
create edge Friend from #11:0 to #11:3
create edge Friend from #11:0 to #11:4
create edge Friend from #11:0 to #11:5
create edge Friend from #11:1 to #11:0
create edge Friend from #11:1 to #11:2
create edge Friend from #11:1 to #11:3
create edge Friend from #11:1 to #11:4
create edge Friend from #11:1 to #11:5
create edge Friend from #11:1 to #11:6
第一个问题:如果用户_0与用户_1是朋友,我们是否需要将它们都存储在Edge中?在上面的示例中,我存储用户11:0到11:1,以及11:1到11:02边缘。我在传统数据库MySQL中这样做,我想知道我现在使用的面向NoSQL的数据库的最佳实践。或者仅为用户11:0到11:1 1 1边保存一行

第二,我如何获得用户_0的所有朋友?请提供sql选择示例。我想从user@RID和user_0的朋友的其他字段的数组中得到结果。因此,如果我们使用2行边(11:0到11:1和11:1到11:0)设计Friend edge,那么所有用户都可以获得所有好友的查询是相同的

如果两个朋友的设计都是1行边,那么查询用户\u 0如何和用户\u 1如何获得所有朋友将是不同的。但是,如果我们将两个朋友关系存储在两行edge中,则跳过此步骤

第三个问题,我如何让我的朋友成为共同的朋友,也就是说,我朋友的朋友也是我的朋友。因此,用户_0如果看到用户_1的朋友,则共同的朋友是11:2,11:3,11:4,11:5。11,6不是用户_0的共同好友用户_1

我认为样本中只有6个或更少的用户就足够了,但我已经创建了10个用户


谢谢

您的数据模型很好。两个用户顶点和一个朋友边就足以实现这一点。它将占用更少的存储空间

我会使用一个链接列表来存储每个用户收到和发送的好友请求。一个用户有多个friendrequest

文档API:

traverse IsFriendsWith from #10:1234 while $depth <= 3 strategy BREADTH_FIRST
图形API:

    select from (
      select 
        expand(unionall(
          outE("IsFriendsWith").inV(), 
          inE("IsFriendsWith").outV()
        ))
        from (
          select 
              expand(unionall(
                outE("IsFriendsWith").inV(), 
                inE("IsFriendsWith").outV()
              ))
          from (
             select expand($u) let $u = first((select from User where uuid = "1"))
          )
        )
    )
  )

      where @rid <> $u and @rid NOT IN $u.both("IsFriendsWith")
以上查询摘自

查看
有关详细信息,请参阅文档。

wow。。。没有人不知道?我回答了你的问题吗?请看我在你回答下面的评论:对不起,两个用户顶点和一个或两个边?如果一个朋友到B,2个顶点,这是正确的,但边应该是一个或两个?只从A到B,还是从A到B,从B到A?