gremlin查询以从属性中删除值之一

时间:2018-07-26 17:52:20

标签: neo4j gremlin

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

例如

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作为数据库。

1 个答案:

答案 0 :(得分:2)

您可以遍历顶点属性,然后过滤匹配的值,然后删除这些属性。另请参阅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]]]