SDK
SDK C# v2.x
2

MUpdateAsync #

Updates multiple documents.

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<JArray> MUpdateAsync(
  string index, 
  string collection, 
  JArray documents, 
  bool waitForRefresh = false, 
  int retryOnConflict = 0);


Argument Type Description
index
string
Index name
collection
string
Collection name
documents
JArray
JArray of documents to update
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

documents #

Each document has the following properties:

Property Type Description
_id
string
Document ID
body
JObject
Document body

Return #

Returns a JObject containing 2 arrays: successes and errors

Each updated document is an object of the successes array with the following properties:

Name Type Description
_id
string
Document ID
_version
int
Version of the document in the persistent data storage
_source
JObject
Document content

Each errored document is an object of the errors array with the following properties:

Name Type Description
document
JObject
Document that cause the error
status
int
HTTP error status
reason
string
Human readable reason

Exceptions #

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

Usage #

Copied to clipboard!
try {
  JArray documents = JArray.Parse(@"
    [
      {
        ""_id"": ""some-id"",
        ""body"": {""category"": ""sedan""}
      },
      {
        ""_id"": ""some-other-id"",
        ""body"": {""category"": ""limousine""}
      }
    ]
  ");
  JObject response = await kuzzle.Document.MUpdateAsync(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  Console.WriteLine(response.ToString());
    /*
    { successes:
      [ { _id: 'some-id',
          _source: { _kuzzle_info: [Object], category: 'sedan' },
          _version: 2,
          result: 'updated',
          created: false,
          status: 200 },
        { _id: 'some-other-id',
          _source: { _kuzzle_info: [Object], category: 'limousine' },
          _version: 2,
          result: 'updated',
          created: false,
          status: 200 } ],
    errors: [] }
    */
  Console.WriteLine($"Successfully updated {((JArray)response["successes"]).Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}