SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

mWrite #

Available since 6.2.0
Available since Kuzzle 1.8.0

Creates or replaces multiple documents directly into the storage engine.

This is a low level route intended to bypass Kuzzle actions on document creation, notably:


mWrite (index, collection, documents, [options])

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
documents
object[]
Array of objects representing the documents
options
object
Query options

documents #

An array of objects. Each object describes a document to create or replace, by exposing the following properties:

  • _id: document unique identifier (optional)
  • body: document content

options #

Additional query options

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
notify
boolean

(false)
if set to true, Kuzzle will trigger realtime notifications
refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Resolves #

Returns a hits array, containing the list of created documents, in the same order than the one provided in the query.

Each created document is an object with the following properties:

NameTypeDescription
_id
string
ID of the newly created document
_version
number
Version of the document in the persistent data storage
_source
object
Created document

If one or more document creations fail, the promise is rejected and the error object contains a partial error error.

Usage #

try {
  const documents = [
    {
      _id: 'panipokari',
      body: {
        licence: 'B',
        _kuzzle_info: { creator: 'bahi', createdAt: 746186305 }
      }
    },
    {
      body: {
        licence: 'B',
        _kuzzle_info: { creator: 'dahi', createdAt: 835005505 }
      }
    }
  ];
  const result = await kuzzle.bulk.mWrite(
    'nyc-open-data',
    'yellow-taxi',
    documents
  );
  console.log(result);
  /*
  { hits:
    [ { _id: 'panipokari',
      _source: {
        "licence": "B",
        "_kuzzle_info": {
          "creator": "bahi",
          "createdAt": 746186305 } },
        _version: 1 },
      { _id: 'AWvlrMIZE7sKlamkyoHr',
        _source: {
          "licence": "B",
          "_kuzzle_info": {
            "creator": "dahi",
            "createdAt": 835005505 } },
        _version: 1 } ],
    total: 2 }
  */
  console.log(`Document creator is ${result.hits[1]._source._kuzzle_info.creator}`);
} catch (error) {
  console.error(error.message);
}