【问题标题】:Gremlin get all vertices that are not connected to meGremlin 获取所有未连接到我的顶点
【发布时间】:2021-03-12 10:31:34
【问题描述】:

我有一个简单的图表,用户可以按产品(高级,普通)。

g.addV('user').as('1')
.property(single, 'name', 'peter')
.addV('product').as('2').property(single, 'premium', false)
.addV('product').as('3').property(single, 'premium', true).property(single, 'order', 1)
.addV('product').as('3').property(single, 'premium', true).property(single, 'order', 2)
.addE('bought').from('1').to('2')

我坚持只需要显示用户未购买的优质产品的查询。提前致谢。

【问题讨论】:

    标签: java gremlin tinkerpop3 amazon-neptune


    【解决方案1】:

    有几种方法可以处理此查询。一种方法是先找到 Peter 已经拥有的所有优质产品,然后再找到不属于该集合的所有优质产品。

    gremlin> g.V().has('name','peter').
    ......1>       out('bought').
    ......2>       has('premium',true).
    ......3>       fold().as('a').
    ......4>   V().hasLabel('product').
    ......5>       has('premium',true).where(without('a'))    
    
    ==>v[42310]
    ==>v[42313]           
    

    已编辑以在末尾添加排序

    gremlin> g.V().has('name','peter').
    ......1>       out('bought').
    ......2>       has('premium',true).
    ......3>       fold().as('a').
    ......4>   V().hasLabel('product').
    ......5>       has('premium',true).where(without('a')).
    ......6>       order().
    ......7>         by('order')     
    
    ==>v[42310]
    ==>v[42313]    
    
       
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      相关资源
      最近更新 更多