MarkLogic 12 Product Documentation
op.arrayAggregate

op.arrayAggregate(
   aggColName as String,
   columndef as ColumnIdentifier,
   [options as String]
) as aggregatedef

Summary

This function constructs an array whose items are the result of evaluating the column for each row in the group or row set. The result is used for building the parameters used by the prototype.groupBy function.

Parameters
aggColName The name to be used for the aggregated column.
columndef The columns to be aggregated. The column can be named with a string or a column function such as op.col, op.viewCol, or op.schemaCol or constructed from an expression with the op.as function.
options The options can take a values key with a 'distinct' value to aggregate the distinct values of the column.

Example

const op = require('/MarkLogic/optic');

op.fromView('main', 'expenses')
   .groupBy('Category', op.arrayAggregate("Expense Array", "Amount"))
   .orderBy('Category')
   .result();
  

Example

const op = require('/MarkLogic/optic');

op.fromView('main', 'expenses')
   .groupBy('Category', op.arrayAggregate("Expense Array", "Amount",{"values":"distinct"}))
   .orderBy('Category')
   .result();
  
Powered by MarkLogic Server | Terms of Use | Privacy Policy