【问题标题】:CosmosDB Graph: How to update a value of property of vertex having multiple values using gremlin?CosmosDB Graph:如何使用 gremlin 更新具有多个值的顶点的属性值?
【发布时间】:2023-03-10 21:00:01
【问题描述】:

假设我的查询是:

g.addV('employee').property('id', 'john').property('country', 'USA').property('country', 'India')

添加具有两个值的属性国家,即美国和印度。

[
 {
  "id":"john",
  "label":"employee",
  "type":"vertex",
  "properties":{
                "country":[
                          {
                           "id":"5dc2aaf6-cb11-4d4a-a2ce-e5fe79d28c80",
                           "value":"USA"
                          },
                          {
                           "id":"fcf4baf6-b4d5-45a3-a4ba-83a859806aef",
                           "value":"India"
                          }
                          ]
                }
 }
]

现在我想更改现有值之一。例如 'India''China'

要查询什么?

【问题讨论】:

    标签: azure-cosmosdb gremlin


    【解决方案1】:

    在单个查询中就是这样:

    g.V().has('id', 'john').
      sideEffect(properties('country').hasValue('India').drop()).
      property(list, 'country', 'China')
    

    【讨论】:

      【解决方案2】:

      我们可以先去掉 'India' 值,然后添加 'China'。我用我这边的以下查询对其进行了测试,它工作正常。

      g.V().has('id', 'john').properties('country').hasValue('India').drop()
      g.V().has('id', 'john').property(list, 'country', 'China')
      

      【讨论】:

      • 是的,这绝对是一个选择。但我一直在寻找一个查询,这样我就不必使用两个不同的查询来更新属性。谢谢:)
      【解决方案3】:

      g.V().has('employee','id', 'john').property('country', 'China')

      【讨论】:

      • 此查询将用“China”替换属性“country”的值,而不是单独的值“India”。结果将是:[{"id":"john","label":"employee","type":"vertex","properties":{"country":[{"id":"3fe29e5e-34b5- 481d-bdeb-672415cc2d6d","value":"China"}]}}] 值 'USA' 和 'India' 都将被替换。
      • 我没有意识到这一点。我认为因为您没有在原始查询中使用list,所以它不会创建list,而是后一个值India 会覆盖之前的值USA。但它在参考文献中。我发现这种行为是不直观的 - 在addV() 之后以一种方式起作用,但在其他方面则不同。
      猜你喜欢
      • 2017-11-30
      • 2012-03-12
      • 1970-01-01
      • 2021-01-24
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多