MarkLogic server-side JavaScript and XQuery

I am just starting using NoSQL MarkLogic DB and trying to choose for me the best query language to learn and use in future. On server side MarkLogic provides the possibility to use JavaScript API or XQuery API.

I want to receive an advice. Which language is better to concentrate on and learn? JavaScript or XQuery?

1 answer

  • answered 2022-05-07 14:06 Mads Hansen

    It doesn't have to be a binary either/or choice. You can use JavaScript AND XQuery (and XSLT) modules.

    Which language to use is largely influenced by your own preference, as well as the type of data you are mostly working with. There are pros and cons for either language, but in terms of APIs and functionality there is almost complete parity.

    If you are already familiar with JavaScript and proficient, then you may find it easier and more approachable.

    XQuery is not as widely known or popular these days, so it is harder to find developers that are already proficient. It may take a while to get familiar with the syntax and understand what a FLWOR and sequences are.

    If you have a lot of XML documents, then XQuery and XSLT would be the natural choice. Building and manipulating XML in JavaScript is kind of awful, in my opinion.

    Because the JavaScript API sits on top of the V8 engine, and XQuery is native code, there are some performance differences. For instance, making a call to a MarkLogic built-in function from JavaScript is slower than if it were done in an XQuery module.

    There are also some limitations for JavaScript modules. For instance, there are memory limits, there is no xdmp:spawn-function() equivalent, and it doesn't have tail call optimization. So, even if your codebase is mostly JavaScript, you may find that there are some circumstances in which an XQuery module might perform better, or be easier to accomplish a particular task.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum