Find “friends of friends” with OrientDB SQL

前端 未结 3 610
自闭症患者
自闭症患者 2021-01-25 06:42

Although one of the most common use cases for demonstrating the capabilities of a graph database, I cannot seem to find a good example or best practice for obtaining \"friends o

3条回答
  •  被撕碎了的回忆
    2021-01-25 07:45

    This should be much simpler:

    select expand(
      bothE('is_friend_with')[status = 'approved'].bothV()
      .bothE('is_friend_with')[status = 'approved'].bothV()
    ) from user where uuid = '95920a96a60c4d40a8f70bde98ae1a24'
    

    With bothE() and then bothV() you get both in/out connections at edge/vertex level.

    In order to exclude current user you could use:

    select expand(
      bothE('is_friend_with')[status = 'approved'].bothV()
      .bothE('is_friend_with')[status = 'approved'].bothV()
      .remove( @this )
    ) from user where uuid = '95920a96a60c4d40a8f70bde98ae1a24'
    

提交回复
热议问题