Loading TOC...

AccessPlan.prototype.map

AccessPlan.prototype.map(
   functionref as String
) as IteratePlan

Summary

This method applies the specified function to each row returned by the plan to produce a different result row.

Parameters
functionref The function to be applied.

Usage Notes

map() is a method of the following classes:

The primary use case for the map() operation is when executing a command from a different context such as when using the /v1/rows endpoint of the REST API and using a library installed in the modules database to postprocess rows on the enode.

When writing an SJS modules that calls result() on a plan with a map() operation, be aware that the result is a JavaScript Iterable instead of a MarkLogic Sequence object. The SJS module must use standard JavaScript techniques for iterating over the Iterable. The REST API does this iteration internally.

Example

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

function secondsMapper(result) {
   result.seconds = new Date().getSeconds();
   return result;
}

employees.orderBy('EmployeeID')
	        .map(secondsMapper)
	        .result();

  

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