【问题标题】:Update a property value without adding an additional value, in gremlin_python在 gremlin_python 中更新属性值而不添加附加值
【发布时间】:2021-05-30 23:53:08
【问题描述】:

更新顶点属性下的docs中,提到可以“更新属性值而不向值集合添加附加值” 通过做
g.V('exampleid01').property(single, 'age', 25)

gremlin_python 中,我无法运行上述查询。
我得到错误:

update_prop_overwrite = g.V().hasLabel('placeholder-vertex').property(single,'maker','unknown').next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'single' is not defined 

如何解决这个问题,以便可以替换 Neptune 中的 Vertex 属性值?
如果没有single,如果值已经存在,则查询会将新属性值附加到属性键。

【问题讨论】:

    标签: gremlin amazon-neptune


    【解决方案1】:

    您需要确保导入single,它可以看到here in the code,并且可以通过以下方式导入:

    from gremlin_python.process.traversal import Cardinality
    

    但是 TinkerPop 文档建议使用以下命令导入所有此类类:

    statics.load_statics(globals())
    

    您可以阅读更多关于 here 的信息。

    【讨论】:

    • 谢谢!,statics.load_statics(globals()) 有效,但 from gremlin_python.process.traversal import Cardinality 似乎没有。不知道为什么,可能是 AWS Neptune 的问题
    【解决方案2】:
    from gremlin_python.process.traversal import Cardinality
    
    g.V().hasLabel('placeholder-vertex').property(Cardinality.single,'maker','unknown').next()
    

    这也应该有效。

    【讨论】:

      【解决方案3】:

      gremlin_python 导入statics

      from gremlin_python import statics
      statics.load_statics(globals())
      
      
      update_prop_overwrite = g.V().hasLabel('placeholder-vertex').property(single,'maker','unknown').next()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-03
        • 2016-05-29
        • 1970-01-01
        • 2015-07-14
        • 1970-01-01
        • 2021-12-12
        • 2021-01-23
        相关资源
        最近更新 更多