SDK
SDK C# v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

MUpdateAsync #

Updates multiple documents.

Returns a partial error (error code 206) if one or more documents cannot 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.

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 #

A JArray representing the replaced documents.

Each document has the following properties:

Property Type Description
_id
string
ID of the newly created document
_version
int
Version of the document in the persistent data storage
_source
JObject
JObject representing the created document
result
string
Set to updated.

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""}
      }
    ]
  ");
  JArray response = await kuzzle.Document.MUpdateAsync(
    "nyc-open-data",
    "yellow-taxi",
    documents);
  Console.WriteLine(response.ToString());
    /*
      [ { _id: 'some-id',
        _source:
          { _kuzzle_info:
            { active: true,
              author: '-1',
              updater: null,
              updatedAt: null,
              deletedAt: null,
              createdAt: 1538639586995 },
            capacity: 4,
            category: "sedan"},
        _version: 2,
        result: 'updated',
        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" },
        _version: 2,
        result: 'updated',
        status: 200 } ]
    */
  Console.WriteLine($"Successfully updated {response.Count} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}