1

Say I have a collection with records structured like so:

<m:m xmlns:m="http://www.m.com/">
    <m:data>
        <z:term xmlns:z="http://z.come/schema/index.html#">
            <z:name>abcd</z:name>
            <z:id>123456789</z:id>
......

And then I want to select records where z:id = whatever or z:name = whatever. How can I do this with queryBuilder?

I've been able to successfully make such queries when there is no namespace. With the namespaces it doesn't seem to work the same way.

1 Answer 1

3

You need to specify the target element using QueryBuilder.element(). The documentation for element() says there are three ways to specify the element's QName:

A name without a namespace can be expressed as a string. A namespaced name can be expressed as a two-item array with uri and name strings or as an object returned by the queryBuilder#qname function.

var ml = require('marklogic');
var conn = require('./config.js').connection;
var db = ml.createDatabaseClient(conn);
var qb = ml.queryBuilder;

db.documents.query(
  qb.where(
    qb.value(qb.element(['http://z.come/schema/index.html#', 'id']), '123456789')
  )
).result()
.then(function(docs) {
  console.log('This search found: ' + JSON.stringify(docs[0]));
})
.catch(function(error) {
  console.log('something went wrong: ' + error);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Or, instead of the array, you can use the qb.qname() function: docs.marklogic.com/jsdoc/queryBuilder.html#qname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.