transform.aggregate
aggregate(config: AggregateConfig, options?: AggregateOptions): Promise<TransformResult>Compute an aggregate value (count, sum, average, max, min, concatenate, takeFirst, or custom) from a neighbor property and write the result onto each root node.
The traversal starts at every visible node that matches the to category filter
(or all visible nodes when to is omitted). Neighbors up to depth hops away
that match the from category filter contribute their sourceProperty values.
The aggregated result is stored in targetProperty (default: "<formula>_<sourceProperty>").
No nodes are deleted. The operation is recorded in history as "AggregateProperties" and
is fully undoable via api.history.undo().
config | AggregateConfig | formula: the aggregation formula; sourceProperty: the neighbor property to read. |
options | AggregateOptions | Optional: to/from category filters; depth (default 1); along relationship
filter; targetProperty overrides the default output key; separator for concatenate;
formulaFn required when formula is "custom". |
Returns: Promise<TransformResult>
Example
// Count orders per customer
await api.transform.aggregate(
{ formula: "count", sourceProperty: "orderId" },
{ to: "Customer", from: "Order", targetProperty: "orderCount" },
);