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.

Signature

Copied to clipboard!
std::string mUpdate(
    const std::string& index,
    const std::string& collection,
    const std::string& documents);

std::string mUpdate(
    const std::string& index,
    const std::string& collection,
    const std::string& documents,
    const kuzzleio::query_options& options);

Arguments

Argument Type Description
index
const std::string&
Index name
collection
const std::string&
Collection name
documents
const std::string&
JSON string representing the documents to update
options
kuzzleio::query_options*
Query options

options

Additional query options

Option Type
(default)
Description
queuable
bool

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
const std::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

Return

A JSON string representing an object containing the following properties:

Property Type Description
hits
object[]
Array of updated documents
total
number
Total documents updated

Exceptions

Throws a kuzzleio::KuzzleException if there is an error. See how to handle errors.

Usage

Copied to clipboard!
try {
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-id", R"({"capacity": 4})");
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-other-id", R"({"capacity": 7})");

  std::string documents = R"(
    [
      {
        "_id": "some-id",
        "body": {"category": "sedan"}
      },
      {
        "_id": "some-other-id",
        "body": {"category": "limousine"}
      }
    ]
  )";

  std::string response = kuzzle->document->mUpdate(
    "nyc-open-data",
    "yellow-taxi",
    documents);

  std::cout << response << std::endl;
    /*
    {  hits:
      [ { _id: 'some-id',
        _source:
          { _kuzzle_info:
            { active: true,
              author: '-1',
              updater: null,
              updatedAt: null,
              deletedAt: null,
              createdAt: 1538639586995 },
            capacity: 4,
            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:
            { active: true,
              author: '-1',
              updater: null,
              updatedAt: null,
              deletedAt: null,
              createdAt: 1538639586995 },
            capacity: 4,
            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 }
  */
  std::cout << "Successfully updated 2 documents" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}