update #
Updates a document content.
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 #
std::string update(
const std::string& index,
const std::string& collection,
const std::string& id,
const std::string& document);
std::string update(
const std::string& index,
const std::string& collection,
const std::string& id,
const std::string& document,
const kuzzleio::query_options& options);
Arguments #
Argument | Type | Description |
---|---|---|
index | const std::string& | Index name |
collection | const std::string& | Collection name |
id | const std::string& | Document ID |
document | const std::string& | JSON string representing the document |
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 document creation result.
Property | Type | Description |
---|---|---|
_id | string | ID of the newly created document |
_version | number | Version of the document in the persistent data storage |
result | string | Set to updated in case of success |
Exceptions #
Throws a kuzzleio::KuzzleException
if there is an error. See how to handle errors.
Usage #
try {
kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-id", R"({"capacity": 4})");
std::string response = kuzzle->document->update(
"nyc-open-data",
"yellow-taxi",
"some-id",
R"({"category": "suv"})");
std::cout << response << std::endl;
/*
{
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "some-id",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
*/
std::cout << "Document successfully updated" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
std::cerr << e.what() << std::endl;
}