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.

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.


mUpdate(index, collection, documents, [options]);
ArgumentTypeDescription
indexstringIndex name
collectionstringCollection name
documentsarray<object>Array of documents to update
optionsobjectQuery options

Options #

Additional query options

OptionsType
(default)
Description
queuableboolean
(true)
If true, queues the request during downtime, until connected to Kuzzle again
refreshstring
("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)
retryOnConflictint
(0)
The number of times the database layer should retry in case of version conflict

Resolves #

Resolves to an object containing the updated documents.

PropertyTypeDescription
hitsarray<object>Updated documents
totalnumberTotal updated documents

Usage #

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(
    'nyc-open-data',
    'yellow-taxi',
    documents
  );
  console.log(response);
  /*
    { 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 }
  */
  console.log('Success');
} catch (error) {
  console.error(error.message);
}