Command update()
will update property values (except ID) of existing nodes/edges based on Ultipa filter.
Failure occurs when trying to update ID, or when the provided FROM/TO does not exist in the graph.
When update operation is triggered:
- the missing custom properties will remain unchanged
- the custom properties provided in the wrong data type will be using default value
Update operation will induce redundant data into the GraphSet and reduce the query efficiency. It is strongly suggested to be cleared on a regular basis, see command
compact()
in the previous chapter.
It is not suggested to execute Update operation after streaming return of an algorithm, see details on
stream()
in document Ultipa Graph Analytics & Algorithms - Using Algorithms - Execution Method.
Syntax:
- Statement alias: supported (NODE or EDGE)
// To update N nodes in the current graphset
update().nodes(<filter>)
.set({<property1>: <value1>, <property2>: <value2> ...})
.limit(<N>)
// To update N edges in the current graphset
update().edges(<filter>)
.set({<property1>: <value1>, <property2>: <value2> ...})
.limit(<N>)
Sample graph: (to be used for the following examples)

create().node_schema("account").edge_schema("follow")
create().node_property(@account, "name").edge_property(@follow, "time", datetime)
insert().into(@account).nodes([{_id:"U001", _uuid:1, name:"Jason"}, {_id:"U002", _uuid:2, name:"Tim"}, {_id:"U003", _uuid:3, name:"Grace"}, {_id:"U004", _uuid:4, name:"Ted"}])
insert().into(@follow).edges([{_uuid:1, _from_uuid:4, _to_uuid:1, time:"2021-09-10"}, {_uuid:2, _from_uuid:3, _to_uuid:2, time:"2020-03-12"}, {_uuid:3, _from_uuid:4, _to_uuid:2, time:"2023-07-30"}])
Example: Update name of any all nodes to '(none)'
update().nodes().set({name: "(none)"}) as nodes
return nodes{*}
| _id | _uuid | name |
|------|-------|--------|
| U001 | 1 | (none) |
| U002 | 2 | (none) |
| U003 | 3 | (none) |
| U004 | 4 | (none) |
Example: Update name of the first two found nodes to '(none)'
update().nodes().set({name: "(none)"}).limit(2) as nodes
return nodes{*}
| _id | _uuid | name |
|------|-------|--------|
| U001 | 1 | (none) |
| U002 | 2 | (none) |
Example: Update edges whose time is later than '2020-01-01', add their time by one day
update().edges({time > "2020-01-01"}).set({time: dateAdd(time,1,"day")}) as edges
return edges{*}
| _uuid | _from | _to | _from_uuid | _to_uuid | time |
|-------|-------|-------|------------|----------|---------------------|
| 2 | U003 | U001 | 3 | 1 | 2020-03-13 00:00:00 |
| 3 | U004 | U002 | 4 | 2 | 2020-07-31 00:00:00 |
Example: Prompt error when trying to update ID
update().nodes({_id == "U001"}).set({_id: "U010", _uuid: 10}) as nodes
return nodes{*}
update _id or _uuid is not allowed