skip to Main Content

I have a query that looks something like the following

g.V('9999').hasLabel('someLabel').
  properties('PropertyName').
  hasId('1234').
  property('currentDate',12/12/2023).
  property('previousDate',10/10/2023)`

Using this query when an Id matches the passed value on hasId the data needs to be updated. I’m able to update currentDate & previousDate, which is a meta property, on the following data, however I’d also like to update the ‘value’ field which is on the same level as the ‘id’ field. My question is how do I tweak the query to also update the value along with the Dates.

[
  {
    "id": "1234",
    "value": "value",
    "label": "PropertyName",
    "properties": {
      "currentDate": 12/12/2023,
      "previousDate": 10/10/2023
    }
  }
]

I tried using Where or Find but it doesn’t seem to help or maybe I didn’t use it the right away

2

Answers


  1. Chosen as BEST ANSWER

    Thanks but it is a vertex with meta properties on it, like below

        "someLabel": [
                {
                  "id": "1234",
                  "value": "value",
                  "properties": {
                  "currentDate": 12/12/2023,
                  "previousDate": 10/10/2023
                  }
                }
              ]
    

    Now the provided solution is not working for the situation because instead of setting the value to "new-value" where id is '1234' instead it adds a new key-value pair as "value": "new-value" to it

        "someLabel": [
                {
                  "id": "1234",
                  "value": "value",
                  "properties": {
                  "currentDate": 12/12/2023,
                  "previousDate": 10/10/2023
                  }
                },
              "id": "30628eea-b97a-40c9-a05f-d1e6267e8846",
              "value": "new-value",
              ]
    
    

  2. The element step that was quite recently added to Gremlin would make this really easy. Given CosmosDB is using an old Gremlin version, perhaps you can try something like this:

    g.V('9999').hasLabel('someLabel').as('a').
      properties('PropertyName').
      hasId('1234').
      property('currentDate',12/12/2023).
      property('previousDate',10/10/2023).
      select('a').
      property('value',<new-value>)
    

    Alternatively, you could wrap part of the query with a sideEffect step. For example:

    g.V('9999').hasLabel('someLabel').
      sideEffect(
        properties('PropertyName').
        hasId('1234').
        property('currentDate',12/12/2023).
        property('previousDate',10/10/2023)
      )
      property('value',<new-value>)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search