0

我是图形数据库和 Gremlin 的新手。我想要实现的是向数据库提出一个简单的问题。提供实体的 id 和文件的 id,我想找到通过共享访问此文件的所有其他实体,并返回具有共享属性“类型”的结果。这是图表本身:简单图

我尝试了什么:

g.V("Enity:1").out("Created").hasLabel("Share").where(out("Shared").hasId("File:1")).in("Access").path()

这让我回想起:

[
  {
    //Omitted empty aray
    "objects": [
      {
        "id": "dseg:/Entity/1",
        "label": "Entity",
        "type": "vertex",
        "properties": {}
      },
      {
        "id": "dseg:/Share/1",
        "label": "Share",
        "type": "vertex",
        "properties": {}
      },
      {
        "id": "dseg:/Entity/1",
        "label": "Entity",
        "type": "vertex",
        "properties": {}
      }
    ]
  },
  {
    //Omitted empty aray
    "objects": [
      {
        "id": "dseg:/Entity/1",
        "label": "Entity",
        "type": "vertex",
        "properties": {}
      },
      {
        "id": "dseg:/Share/1",
        "label": "Share",
        "type": "vertex",
        "properties": {}
      },
      {
        "id": "dseg:/Entity/3",
        "label": "Entity",
        "type": "vertex",
        "properties": {}
      }
    ]
  }
]

它显示了从入口点(实体:1)到目标实体 2 和 3 的路径

我的技术细节问题:有没有办法在我选择的 Entity:1 或中间顶点之后开始收集 path() ,这样我就只能得到有权访问它的 Share + Entity ?

4

1 回答 1

2

你只需要告诉路径步骤从哪里开始。你可以这样做:

gremlin> g.V("entity:1").
......1>   out("Created").
......2>   hasLabel("Share").
......3>   where(out("Shared").hasId("File:1")).as('a').
......4>   in("Access").
......5>   path().from('a').by('Type').by()
==>[RO,v[entity:2]]
==>[RO,v[entity:3]]

另一种方法是:

gremlin> g.V().
......1>   hasLabel('Share').
......2>   where(out('Shared').hasId('File:1')).
......3>   where(__.in('Created').hasId('entity:1')).
......4>   in('Access').
......5>   path().by('Type').by()
==>[RO,v[entity:2]]
==>[RO,v[entity:3]]
于 2022-02-12T21:05:10.277 回答