【问题标题】:gremlin query to remove one of the value from propertygremlin 查询以从属性中删除其中一个值
【发布时间】:2018-07-26 17:52:20
【问题描述】:

我正在尝试找到一种方法来删除顶点上的属性(字符串列表)中的特定值。顶点具有多个属性,其中一个属性是字符串列表。

例如

gremlin> g.V().hasLabel('ACCOUNT').or(has('Name', '123')).properties()
==>vp[Value->a]
==>vp[Value->b]
==>vp[Value->c]

例如,我正在寻找一个查询以从列表中删除属性值“a”,并且在操作之后列出的关于查询的 o/p 应该是。

gremlin> g.V().hasLabel('ACCOUNT').or(has('Name', '123')).properties()
==>vp[Value->b]
==>vp[Value->c]

我使用 neo4j 作为我的数据库。

【问题讨论】:

    标签: neo4j gremlin


    【解决方案1】:

    您可以遍历顶点属性,然后过滤匹配的值,然后删除这些属性。另请参阅 TinkerPop 文档中的vertex property examples

    gremlin> Gremlin.version()
    ==>3.2.9
    gremlin> // create the vertices
    gremlin> g.addV('ACCOUNT').
    ......1>     property(list, 'Value', 'a').
    ......2>     property(list, 'Value', 'b').
    ......3>     property(list, 'Value', 'c').
    ......4>     iterate()
    gremlin> g.addV('PERSON').
    ......1>     property('Name', '123').
    ......2>     property(list, 'Value', 'a').
    ......3>     property(list, 'Value', 'b').
    ......4>     property(list, 'Value', 'c').
    ......5>     iterate()
    
    gremlin> // show all properties (before)
    gremlin> g.V().or(hasLabel('ACCOUNT'), has('Name', '123')).
    ......1>     project('label', 'props').
    ......2>     by(label()).by(properties().fold())
    ==>[label:ACCOUNT,props:[vp[Value->a],vp[Value->b],vp[Value->c]]]
    ==>[label:PERSON,props:[vp[Value->a],vp[Value->b],vp[Value->c],vp[Name->123]]]
    
    gremlin> // drop only the matching property
    gremlin> g.V().or(hasLabel('ACCOUNT'), has('Name', '123')).properties('Value').
    ......1>     hasValue('a').
    ......2>     drop().iterate()
    
    gremlin> // show all properties (after)
    gremlin> g.V().or(hasLabel('ACCOUNT'), has('Name', '123')).
    ......1>     project('label', 'props').
    ......2>     by(label()).by(properties().fold())
    ==>[label:ACCOUNT,props:[vp[Value->b],vp[Value->c]]]
    ==>[label:PERSON,props:[vp[Value->b],vp[Value->c],vp[Name->123]]]
    

    【讨论】:

    • 他的例子中实际上只有一个顶点,Name 属性与ACCOUNT 顶点相关。 or() 步骤毫无意义,并增加了混乱。此外,您不需要 lambda-filter 步骤,只需 ...properties('Value').hasValue('a')
    • 谢谢,你是对的。我会用hasValue('a') 更新答案。最初的问题在顶点上根本没有 Name 属性,否则它会被列为结果中的属性之一。这就是为什么我在示例中创建了 2 个单独的顶点;)
    猜你喜欢
    • 2022-09-30
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多