【问题标题】:How to add a new property to an existing vertex in gremlin?如何向 gremlin 中的现有顶点添加新属性?
【发布时间】:2014-12-25 08:19:34
【问题描述】:

我很难找到使用 gremlin 向现有顶点添加新属性的方法。 要添加的前属性:值为“anna”的属性“name”。

首先,我尝试找到要添加属性的顶点。我这样做: g.v(id),其中 id 是我要查找的顶点的 id。

然后我尝试通过执行以下操作将属性添加到顶点: g.v(id).property("name","anna"),但这不起作用并给我一个错误提示:

"message":"","error":"javax.script.ScriptException: groovy.lang.MissingMethodException: No
signature of method: groovy.lang.MissingMethodException.property() is applicable for argument types: (java.lang.String, java.lang.String) values:

这里在“Mutation the graph”下的http://www.tinkerpop.com/docs/3.0.0.M1/#giraph-gremlin 说这是向现有顶点添加新属性的方法。

有什么建议吗?

【问题讨论】:

  • 您正在阅读 TP3 文档,但看起来您正在使用 TP2。在 TP2 中是g.v(id).setProperty("name","anna")
  • 谢谢,这对我有用!

标签: graph gremlin rexster


【解决方案1】:

您可以通过sideEffect 实现这一目标:

g = TinkerGraphFactory.createTinkerGraph()
g.V[0].map
==>{name=lop, lang=java}
g.V[0].sideEffect{it.foo = 'bar'}
g.V[0].map
==>{name=lop, foo=bar, lang=java}

我想在脚本中您需要在修改语句的末尾添加一个.iterate()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 2019-10-29
    • 1970-01-01
    相关资源
    最近更新 更多