Conditionally update one vertex property when another property matches a certain provided value

98 Views Asked by At

I have a vertex with meta properties on it, like below, and need to update the properties & the attached meta properties. 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.

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

Query I tried:

`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>)
`

I tried the query mentioned above but it's not working for updating the value because instead of updating the value to "new-value" where id is '1234', it adds a new key-value pair as "value": "new-value" to it, as you can see in this dataset here.

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

The expected dataset;

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

There are 1 best solutions below

1
Balaji On

Update one vertex property when another property matches a certain provided value:

Below are the steps I followed:

  • I used .hasLabel('someLabel') to filter vertices by their label. This selects only vertices with the label someLabel.

  • To filter the vertices based on the value of their "id" attribute, I used .has('id', '1234').

  • .property('value','new value') This line modifies the specified vertex's value property.

  • The "value" property now has the new value as its value.

Query I used:

g.V()
  .hasLabel('someLabel')
  .has('id', '1234')
  .property('value', 'new value')

Before running the query:

Input: enter image description here

After running the query:

Output: enter image description here