SDK Javascript v6.x

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.

mUpdate #

Updates multiple documents.

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

Conflicts may occur if the same document gets updated multiple times within a short timespan in a database cluster.

You can set the retryOnConflict optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error.

Copied to clipboard!
mUpdate(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
queuable boolean
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)
retryOnConflict int
The number of times the database layer should retry in case of version conflict

Resolves #

Resolves to an object containing the updated documents.

Property Type Description
hits array<object> Updated documents
total number Total updated documents

Usage #

Copied to clipboard!
const doc1 = { capacity: 4 };
const doc2 = { capacity: 7 };
try {
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc1, 'some-id');
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc2, 'some-other-id');
  const documents = [
      _id: 'some-id',
      body: { category: 'sedan' }
      _id: 'some-other-id',
      body: { category: 'limousine' }
  const response = await kuzzle.document.mUpdate(
    { hits:
    [ { _id: 'some-id',
        _source: { _kuzzle_info: [Object], category: 'sedan' },
        _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: [Object], category: 'limousine' },
        _index: 'nyc-open-data',
        _type: 'yellow-taxi',
        _version: 2,
        result: 'updated',
        _shards: { total: 2, successful: 1, failed: 0 },
        created: false,
        status: 200 } ],
    total: 2 }
} catch (error) {