Support of MarkLogic for Node.js


Objects

Icon Description
NodeJS Marklogic database
NodeJS Marklogic collection

Supported libraries

Library require Versions
MarkLogic marklogic 1.x, 2.x, 3.x, 4.x

The links will be created between the caller NodeJS Objects and NodeJS Marklogic collection.

Link Type Supported APIs
useSelectLink query
read
useInsertLink write
useUpdateLink patch
useDeleteLink remove
removeAll

What results can you expect?

This declaration will create a MarkLogic database and a collection:

var marklogic = require('marklogic');
var db = marklogic.createDatabaseClient(conn);

// create Collection countries
var q = marklogic.queryBuilder;
db.documents.query(
  q.where(
    q.collection('countries'),
    q.value('region', 'Africa'),
    q.or(
      q.word('background', 'France'),
      q.word('Legal system', 'French')
    )
  )
).result(function(documents) {
  documents.forEach(function(document){
    console.log(JSON.stringify(document));
  });
});

This declaration will create a MarkLogic collection “fake data” and a useDeleteLink to the collection “fake data”:

db.documents.removeAll({collection: 'fake data'})
.result()
.then(response => console.log('Removed collection ' + response.collection))
.catch(error => console.log(error));

This declaration will create a MarkLogic collection “fake data” and a useInsertLink to the collection “fake data”:

db.documents.write(
  data.map((item) => {
    return {
      uri: `/${item.guid}.json`,
      contentType: 'application/json',
      collections: ['fake data'],
      content: item
    }
  })
)
.result()
.then(response => console.dir(JSON.stringify(response)))
.catch(error => console.error(error));