【问题标题】:How to Update the Value of Vertex in Gremlin Server ( Titan 1.0)如何在 Gremlin 服务器中更新 Vertex 的值(Titan 1.0)
【发布时间】:2016-09-14 23:34:41
【问题描述】:

我有一个带有以下详细信息的顶点:

http://localhost:8182/?gremlin=g.V(4192)

{

"requestId": "6ce01f3b-f623-41f6-bb03-dd56014e0701",
"status": 

{

"message": "",
"code": ​200,
"attributes": { }

},
"result": 
{

"data": 

[

{

"id": ​4192,
"label": "person",
"type": "vertex",
"properties": 

{

"name": 

[

{
    "id": "170-38g-sl",
    "value": "marko2"
}

],
"age": 
[

                    {
                        "id": "1l8-38g-28lh",
                        "value": ​29
                    }
                ]
            }
        }
    ],
    "meta": { }
}

}

我想更新顶点的名称:

我尝试了以下查询:

g.V(4192).setProperty('name','William')

但它没有更新,它给出了错误

{

 "message": "Error encountered evaluating script: g.V(4192).setProperty('name','William')"

}

【问题讨论】:

    标签: graph titan gremlin tinkerpop3 gremlin-server


    【解决方案1】:

    Traversal 上没有名为“setProperty()”的方法。你会这样做:

    g.V(4192).property('name','William')
    

    请参阅TinkerPop documentation 中的完整步骤列表。

    您也可以直接使用 Vertex 并执行以下操作:

    v = g.V(4192).next()
    v.property('name','william')
    

    【讨论】:

    • 如何一次更新多个值?我试过 g.V(4192).property('name','William2','age',30)。但它不工作
    • 试试g.V(4192).property('name','William2').property('age',30)
    【解决方案2】:

    如果property() 方法生成一个值数组而不是更新值,请像这样使用Cardinality

    g.V(4192)v.property(Cardinality.single, 'name', 'william').next()
    

    这将替换属性值而不是追加到列表中。

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 2017-11-30
      • 2016-09-23
      • 2013-04-30
      • 2017-11-07
      • 2017-10-17
      • 2017-03-11
      • 2018-09-23
      • 2016-10-26
      相关资源
      最近更新 更多