The update() clauses is used to update values of properties (except _id and _uuid) of nodes and edges that meet the given conditions.
Syntax// Update nodes update().nodes(<filter>) .set({<property1>: <value1>, <property2>: <value2> ...}) .limit(<N>) // Update edges update().edges(<filter>) .set({<property1>: <value1>, <property2>: <value2> ...}) .limit(<N>)
nodes() or edges() method. Leave it blank to specify all nodes or edges.set() method.limit() method to restrict the number of nodes or edges to update.
Run these UQLs row by row in an empty graphset to create this graph:
UQLcreate().node_schema("user").edge_schema("follow") create().node_property(@user, "name").node_property(@user, "age", int32).edge_property(@follow, "time", datetime)Click to expand
UQLupdate().nodes({name == "Tim"}).set({name: "Tom"})
This updates the name property of nodes whose name is Tim. The node with _id U002 is updated.
UQLupdate().edges({time > "2021-5-1"}).set({time: dateAdd(time, 1, "day")}) as edges return edges{*}
This updates the time property of edges whose time is later than 2021-5-1, to one day after.
Result:
| _uuid | _from | _to | _from_uuid | _to_uuid | time |
|---|---|---|---|---|---|
| 1 | U004 | U001 | 4 | 1 | 2021-09-11 00:00:00 |
| 3 | U004 | U002 | 4 | 2 | 2023-07-31 00:00:00 |
UQLupdate().nodes().set({age: age + 1}) as n return table(n.name, n.age)
Result:
| name | age |
|---|---|
| Jason | 31 |
| Tom | null |
| Grace | 26 |
| Ted | 27 |
UQLupdate().nodes({@user}).set({name: lower(name)}).limit(2) as nodes return nodes{*}
This updates the name property of @user nodes to lowercase characters, but only for two nodes.
Result:
| _id | _uuid | name | age |
|---|---|---|---|
| U001 | 1 | jason | 31 |
| U002 | 2 | tom | null |
_uuid or _id is included in the set() method, as unique identifier properties cannot be updated.