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]);
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) |
retryOnConflict | int ( 0 ) | 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 #
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);
}
Edit this page on Github(opens new window)