首页 > 解决方案 > 如何在图数据库中查询多个顶点和边

问题描述

我正在使用 DSE 图。我有一个这样的模型:

AccountGroup“由”帐户(AccountGroup -> Account)组成。配置文件“accesses_to”帐户(配置文件 -> 帐户)。

现在给定一个 account_id,我需要返回与该 Account 相关的所有顶点和边。

我的 gremlin 代码如下所示:

g.V().has('Account', 'account_id', '123456').in().hasLabel('AccountGroup')

这只会为 Account 返回一个 AccountGroup。如何编写获取所有 Account、AccountGroup 和 Profile 的查询?

标签: gremlin

解决方案


我认为您想要所有相关顶点的路径或只是一棵树。所以它是:

g.V().has('Account', 'account_id', '123456').
  inE('consists of','accesses_to').outV().
  path()

... 或这个:

g.V().has('Account', 'account_id', '123456').
  inE('consists of','accesses_to').outV().
  tree()

后者是一种更紧凑的格式,但在客户端可能更难处理。


推荐阅读