Loading TOC...


   $keys as columnIdentifier[],
   [$counter as columnIdentifier?]
) as ModifyPlan


This method counts values for multiple grouping key columns.

The method produces the same output as a prototype.groupToArrays function with single-column groups and a count aggregate.

$keys This parameter specifies the list of column keys for performing counts. For each column, the operation determines the unique values of that column and produces a separate count for the rows with that value.

A column can be named with a string or a column parameter function such as op.col or constructed from an expression with the op.as function. The facet can be named by providing a op.namedGroup that takes exactly one column.

$counter Specifies what to count over the rows for each unique value of each key column.

By default, the operation counts the rows. To count the values of a column instead, specify the column to count with this parameter. To count documents, specify a fragment id column with op.fragmentIdCol.

Usage Notes

The op.facetBy function is a convenience for executing a prototype.groupToArrays equivalent to:

function facetBy(rowQuery, keys, counter) {
   return rowQuery.groupToArrays(keys, op.count('count', counter));

See Also


// Calculate the total expenses separately for each category and for each location.

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

op.fromView('main', 'expenses')
   .facetBy(['Category', 'Location'])


// Filter the category and location facets by different criteria.

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

const expenses = op.fromView('main', 'expenses');
const catFacet =
   .where(op.eq(op.col('Location'), 'New York'))
   .facetBy(op.namedGroup('Categories', 'Category'));
const locFacet =
   .where(op.eq(op.col('Category'), 'Payroll'))
   .facetBy(op.namedGroup('Locations', 'Location'));

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.