Loading TOC...

MarkLogic Server 11.0 Product Documentation
op.case

op.case(
   whenExpression as String,
   valueExpression as String
) as valueExpression

Summary

This function returns the specified valueExpression if the specified valueExpression is true. Otherwise, it returns null.

Parameters
whenExpression One or more op.when expressions.
valueExpression The value expression to return if none of the op.when expressions is true.

Example

const op = require('/MarkLogic/optic');
const employees = op.fromView('main', 'employees');

employees.select(['EmployeeID', op.as('cased', op.case([
                   op.when(op.eq(op.col('EmployeeID'), 2), 'second'),
                   op.when(op.eq(op.col('EmployeeID'), 3), 'third')],
                   'otherwise'))])
          .result();
  

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