Marklogic | NodeJS API - Field Attribute Request

I have a json structure something like

{
   foo:"bar",
   keyPhrases:[
      {key: "random thing", value: 5},
      {key: "another random", value: 3}
   ]
}

      

How can I make a text request for keyPhrases.key? I tried

qb.word('keyPhrases.key', 'random')

or

qb.word(qb.property('keyPhrases.key'), 'random')

      

and it doesn't work. Any ideas? I know this is possible with QBE, but for Marklogic NodeJS API, you cannot specify a collection, and I need to.

+3


source to share


1 answer


You need qb.scope () .

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.collection('test'),
    qb.scope(qb.property('keyPhrases'), qb.word('key', 'random'))
  )
  .withOptions({metrics: true})
).result()
.then(function(docs) {
  console.log('This search found: ' + JSON.stringify(docs[1]));
})
.catch(function(error) {
  console.log('something went wrong: ' + error);
});

      



Alternatively, you can create a field and query based on routes.

+4


source







All Articles