Support of MarkLogic for Node.js


Objects

IconDescription
NodeJS Marklogic database
NodeJS Marklogic collection

Supported libraries

LibraryrequireVersions
MarkLogicmarklogic1.x, 2.x, 3.x, 4.x

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

Link TypeSupported APIs
useSelectLinkquery
read
useInsertLinkwrite
useUpdateLinkpatch
useDeleteLinkremove
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));