PreparePlan.prototype.map( functionref as String ) as IteratePlan
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. |
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.
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: Get the most useful answers to questions from the MarkLogic community, or ask your own question.