mReplace

Replaces multiple documents.

Throws a partial error (error code 206) if one or more documents can not be replaced.


Copied to clipboard!
mReplace(index, collection, documents, [options]);
Argument Type Description
index string Index name
collection string Collection name
documents array<object> Array of documents to update
options object Query options

Options

Additional query options

Options Type
(default)
Description
queuable boolean
(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh string
("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Resolves

Resolves to an object containing the replaced documents.

Property Type Description
hits array<object> Replaced documents
total number Total replaced documents

Usage

Copied to clipboard!
try {
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', {}, 'some-id');
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', {}, 'some-other-id');

  const documents = [
    {
      _id: 'some-id',
      body: { capacity: 4 }
    },
    {
      _id: 'some-other-id',
      body: { capacity: 4 }
    }
  ];

  const response = await kuzzle.document.mReplace(
    'nyc-open-data',
    'yellow-taxi',
    documents
  );

  console.log(response);
  /*
  {  hits:
    [ { _id: 'some-id',
      _source:
        { _kuzzle_info:
          { active: true,
            author: '-1',
            updater: null,
            updatedAt: null,
            deletedAt: null,
            createdAt: 1538639586995 },
          capacity: 4 },
      _index: 'nyc-open-data',
      _type: 'yellow-taxi',
      _version: 2,
      result: 'updated',
      _shards: { total: 2, successful: 1, failed: 0 },
      created: false,
      status: 200 },
    { _id: 'some-other-id',
      _source:
        { _kuzzle_info:
          { active: true,
            author: '-1',
            updater: null,
            updatedAt: null,
            deletedAt: null,
            createdAt: 1538639586995 },
          capacity: 4 },
      _index: 'nyc-open-data',
      _type: 'yellow-taxi',
      _version: 2,
      result: 'updated',
      _shards: { total: 2, successful: 1, failed: 0 },
      created: false,
      status: 200 } ],
  total: 2 }
  */
  console.log('Success');
} catch (error) {
  console.error(error.message);
}