Loading TOC...

MarkLogic Server 11.0 Product Documentation
fn.exactlyOne

fn.exactlyOne(
   arg as Sequence
) as Item

Summary

Returns $arg if it contains exactly one item. Otherwise, raises an error [err:FORG0005].

For detailed type semantics, see Section 7.2.16 The fn:zero-or-one, fn:one-or-more, and fn:exactly-one functions[FS].

Parameters
arg The sequence of items. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array.

Example

fn.exactlyOne(["hello"])

=> ["hello"]

fn.exactlyOne(xdmp.arrayValues(["hello", "goodbye"]))

=> XDMP-NOTONEITEM exception (because there are 2 items)

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