【问题标题】:Cosmos DB Gremlin "project" not producing expected resultsCosmos DB Gremlin“项目”未产生预期结果
【发布时间】:2018-08-23 13:06:51
【问题描述】:

我有以下遍历表明所选顶点有 14 条边标记为“跟随”。

 g.V().has('user','email','me@email.com').project('name','email','follow-edges').by('name').by('email').by(outE().hasLabel('follows').project('id','inV').by('id').by('inV'))

这会产生以下结果:

[{
"name": "David",
"email": "me@email.com",
"follow-edges": 14}]

但是当我想投影“跟随”Edge 的 id 和 inV id 时,我只会得到一个结果项。

g.V().has('user','email','david@me.com').project('name','email','follow-edges').by('name').by('email').by(outE().hasLabel('follows').project('edge-id', 'inV-id').by('id').by('inV'))

结果:

[{
"name": "David",
"email": "me@email.com",
"follow-edges": {
  "edge-id": "ccc06183-f4ca-410d-9c3c-9d2dfd93f5f0",
  "inV-id": "f4703a07-f42d-46f9-86be-7f5440f07f12"
}}]

我期待获得所选顶点的所有“跟随”边的列表。类似于Stephen Mallette at this link给出的答案。

有谁知道为什么这不起作用?

【问题讨论】:

    标签: azure-cosmosdb gremlin


    【解决方案1】:

    您需要在by() 中减少匿名遍历中的对象流 - 请注意我添加的fold()

    g.V().has('user','email','david@me.com').
      project('name','email','followedges').
        by('name').
        by('email').
        by(outE().hasLabel('follows').
           project('edge-id', 'inV-id').
             by('id').
             by('inV').fold())
    

    我假设“inV”是一个实际属性,而您并不是想获得边缘的“in vertex”。如果你想获得“在顶点”,那么你需要by(inV().id())

    【讨论】:

    • 太棒了!答案就在眼前!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多