SDK
SDK C# v2.x
2

UpdateAsync #

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.

Arguments #

Copied to clipboard!
public async Task<JObject> UpdateAsync(
  string index,
  string collection,
  string id,
  JObject changes,
  bool waitForRefresh = false,
  int retryOnConflict = 0);


Argument Type Description
index
string
Index name
collection
string
Collection name
id
string
Document ID
changes
JObject
JObject representing the modified fields
waitForRefresh
bool

(false)
If true, 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 JObject representing an object containing the document creation result.

Property Type Description
_id
string
ID of the newly created document
_version
int
Version of the document in the persistent data storage
result
string
Set to updated in case of success

Exceptions #

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

Usage #

Copied to clipboard!
try {
  await kuzzle.Document.CreateAsync(
    "nyc-open-data",
    "yellow-taxi",
    JObject.Parse(@"{""capacity"": 4}"),
    id: "some-id");
  JObject response = await kuzzle.Document.UpdateAsync(
    "nyc-open-data",
    "yellow-taxi",
    "some-id",
    JObject.Parse(@"{""category"": ""suv""}"));
  Console.WriteLine(response.ToString(Formatting.None));
  /*
  {
    "_id": "some-id",
    "_version": 2
  }
  */
  Console.WriteLine("Document successfully updated");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}