Server-side JavaScript

Working Together

MarkLogic provides two languages for code running in the database: Server-side JavaScript and XQuery. These languages can be used together, allowing mixed teams to make use of each other's work.

Calling XQuery from Server-side JavaScript

JavaScript modules can import XQuery modules and access public functions and variables, just as an importing XQuery file could. XQuery names are automatically converted to lowerCamelCase in JavaScript. This gives the JavaScript developer access to existing XQuery code, whether developed by MarkLogic or by an in-house team.

The example below uses MarkLogic's Admin API to create a dateTime range index on the "registered" property.

Use CommonJS syntax to import an XQuery library module. Imported functions are available in their lowerCamelCase form. For example, my:do-something(…) in XQuery would be called as

in JavaScript.

Calling JavaScript from XQuery

XQuery modules can evaluate JavaScript (and SQL and SPARQL). xdmp:javascript-eval() allows access to external variables and does all of the mapping between XQuery and JavaScript data types.

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