Command update()
will update existing nodes/edges based on Ultipa filter.
When executing update()
:
- Find metadata to be updated based on the filtering condition;
- Custom properties provided in the correct data type will be updated;
- Custom properties provided in the wrong data type will be updated as empty string (for string, text, datetime), 0 (for int32, int64, uint32, uint64, float, double), or "1970-01-01 08:00:00 +08:00" (for timestamp);
- The operation fails if the nodes represented by the provided FROM or TO do NOT exist in the graph when updating edges.
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>)
Example: Update the balance of bank card C001 to 300
update().nodes({_id == "C001"})
.set({balance: 300})
Example: Update the score of all bank cards @card to the value of level*balance
update().nodes({@card})
.set({score: level * balance})
Example: Upgrade 5,000 bank cards @card under level 2 but has balance that exceeds 200,000 to the next upper level
update().nodes({@card && level < 2 && balance > 200000})
.set({level: level + 1})
.limit(5000)
Analysis: When the amount of data is too large for the memory to process, parameter limit()
can be used to set the maximum quantity to handle thus to process in batches.
Example: Update the amount of @transaction.no TRX001 to 100
update().edges({@transaction.no == "TRX001"})
.set({amount: 100})