Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

marklogic

marklogic1.7kApache-2.03.6.0

The official MarkLogic Node.js client API.

marklogic, nosql, database, dbms, search, query, json, xml, http, xquery, xpath

readme

MarkLogic Node.js Client API

The MarkLogic Node.js Client API provides access to the MarkLogic database from Node.js applications.

Features

  • Writing, reading, patching, and deleting documents in JSON, XML, text, or binary formats
  • Querying over documents including parsing string queries, extracting properties, and calculating facets
  • Projecting tuples (like table rows) out of documents
  • Single transactions and multi-statement transactions for database changes
  • Writing, reading, and deleting graphs and executing SPARQL queries over graphs
  • Extending the built-in services or evaluating or invoking your own JavaScript or XQuery on the server
  • Basic, digest, certificate, Kerberos, and SAML authentication
  • Import libraries as JavaScript mjs modules
  • Data Services First - MarkLogic's support for microservices
  • Optic query DSL, document matching, relevance, multiple groups
  • Generate query based views, redaction on rows
  • Data Movement SDK - move large amounts of data into, out of, or within a MarkLogic cluster

Getting Started

You can install the marklogic package as a dependency for your Node.js project using npm:

npm install marklogic --save

For Windows OS please use the below for Node Client 2.9.1:

npm install marklogic --save --ignore-scripts

With the marklogic package installed, the following inserts two documents in a collection into the Documents database using MarkLogic's built-in REST server at port 8000:

const marklogic = require('marklogic');

const db = marklogic.createDatabaseClient({
  host:     'localhost',
  port:     '8000',
  database: 'Documents',
  user:     'admin',
  password: 'admin',
  authType: 'DIGEST',
  // enableGzippedResponses is optional and can be set to true in order to request MarkLogic to compress the response for better performance,
    // the client will automatically decompress the response before it returns a value.
  enableGzippedResponses: true
});

// For MarkLogic Cloud
const db = marklogic.createDatabaseClient({
    apiKey:   'changeme',
    host:     'example.beta.marklogic.com',
    authType: 'cloud',
    // basePath is optional.
    basePath: '/marklogic/test',
    // accessTokenDuration (in seconds) is optional and can be used to customize the expiration of the access token.
    accessTokenDuration: 10,
    // enableGzippedResponses is optional and can be set to true in order to request MarkLogic to compress the response for better performance,
    // the client will automatically decompress the response before it returns a value.
    enableGzippedResponses: true
});

// For OAUTH
const db = marklogic.createDatabaseClient({
    host:     'localhost',
    port:     '8000',
    authType: 'oauth',
    oauthToken: '<OAUTH Token>'
});

db.createCollection(
  '/books',
  {author: 'Beryl Markham', ...},
  {author: 'WG Sebald',     ...}
  )
.result(function(response) {
    console.log(JSON.stringify(response, null, 2));
  }, function (error) {
    console.log(JSON.stringify(error, null, 2));
  });

Resources

Code Examples

The Node.js Client API ships with code examples to supplement the examples in the online resources. To run the examples, follow the instructions here:

examples/1readme.txt

Generating Documentation Locally

After installing the project dependencies (including the gulp build system), you can build the reference documentation locally from the root directory of the marklogic package:

npm run doc

The documentation is generated in a doc subdirectory. The documentation can also be accessed online here.

Support

The MarkLogic Node.js Client API is maintained by MarkLogic Engineering. It is designed for use in production applications with MarkLogic Server. Everyone is encouraged to file bug reports, feature requests, and pull requests through GitHub. This input is critical and will be carefully considered, but we can’t promise a specific resolution or timeframe for any request. In addition, MarkLogic provides technical support for release tags of the Node.js Client API to licensed customers under the terms outlined in the Support Handbook. For more information or to sign up for support, visit help.marklogic.com.

changelog

CHANGELOG

3.6.0

New Functionality

  • MarkLogic 12 users can now use the shortestPath and annTopK methods in the Optic plan builder.
  • MarkLogic 12 users can now use the bm25, zero, and random score methods in the Optic plan builder.

Bug Fix

3.5.0

New Functionality

  • Can now use BM25 scoring method for searches. (MarkLogic Server version 12.0.0-EA or higher needed).
  • Can now use vector functionality including Cosine Similarity and others. (MarkLogic Server version 12.0.0-EA or higher needed).

Bug Fix

3.4.0

New Functionality

  • Can now connect to MarkLogic using OAuth token (MarkLogic Server version 11.2.0 or higher needed).
  • Optic Update plans, including DSL queries that perform updates, now require update: true to be included in the options sent to the rows.execute() function. (MarkLogic Server version 11.2.0 or higher needed).
  • Can now perform partial updates on documents via Optic using the new patchBuilder operator. (MarkLogic Server version 11.2.0 or higher needed).
  • Can now capture errors from executing an Optic plan by including the new onError operator. (MarkLogic Server version 11.2.0 or higher needed).

Bug Fix

3.3.1

Bug Fix

  • Fixed a bug where a database property caused a problem when creating a URL path for querying ML.

3.3.0

New Functionality

  • Can now request MarkLogic to compress the response for better performance using enableGzippedResponses (MarkLogic Server version 11.0.0 or higher needed).
  • Can now send string input to cts.point and cts.polygon server functions (MarkLogic Server version 11.1.0 or higher needed).

3.2.0

New Functionality

  • Can now set expiration duration for MarkLogic Cloud access-token.

Improvements and Bug Fixes

3.1.0

New Functionality

  • Can now perform update operations in Optic.
  • Can now submit GraphQL queries.
  • Auto-refresh expired token when using MarkLogic Cloud authentication.

Improvements and Bug Fixes

  • Fix for security vulnerabilities.

3.0.0

New Functionality

  • #614 - Exporting Rows - queryAll api.
  • #644 - Reprocessing documents - transformAll and queryToTransformAll apis.
  • #665 - Deleting Documents - removeAllUris and queryToRemoveAll api.
  • Connect to MarkLogic Cloud using apiKey.

Improvements and Bug Fixes

  • Fix for Dicer and other security vulnerabilities.
  • #540 - Expose total on all responses to documents.query.
  • #592 - Expose op:sample-by in Node Client API.
  • #694 - MarkLogic module v 2.9.1 for Node.js at Windows OS does not work.

2.9.1

Improvements and Bug Fixes

  • Fix for security vulnerabilities (except Dicer).

2.9.0

New Functionality

  • #620 - Exporting Documents - readAll and queryToReadAll apis.
  • #622 - Collecting Document URIs - queryAll api.
  • #629 - Add a category option for reading only the contents of document(s).

Improvements and Bug Fixes

  • #599 - Optic fromSPARQL method support options parameter - Server release 10.0-8 or above required.
  • #638 - (Documentation Fix) - Parameters "start" and "length" for graphs.sparql are renamed to "begin" and "end".
  • #647 - QueryToReadAll on a Query with no results produces no response.

2.8.0

New Functionality

  • #621 - Data Movement in Node.js API - Ingesting Documents using writeAll api.

Improvements and Bug Fixes

  • #270 - Calling methods on resources with arg list throws error.
  • #601 - Regenerate Optic expression functions.

2.7.0

New Functionality

  • #543 - Node-client-api now prefers ipv4 over ipv6.
  • #562 - CtsQueryBuilder is available.
  • #567 - Dynamic interface to Data Service endpoints.
  • #569 - Optic enhancements in 10.0-7 - Server release 10.0-7 or above required.

Improvements and Bug Fixes

  • #485 - Throw error when complexValues is set with a chunked stream.
  • #559 - Throw error on requests with a released client.
  • #565 - Node-client-api now uses Node - 14.
  • #568 - RejectUnauthorized option ignored in webpacked typescript (impacts mlxprs extension in latest VSCode on Mac).
  • #570 - (Documentation Fix) - Changed “testConnection” on DatabaseClient to “checkConnection”.