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.

CreateAsync #

Creates a new document in the persistent data storage.

Throws an error if an ID is provided and if a document with that ID already exists.

Arguments #

public async Task<JObject> CreateAsync( 
  string index, 
  string collection, 
  JObject content, 
  string id = null, 
  bool waitForRefresh = false);

OptionType
(default)
Description
index
string
Index name
collection
string
Collection name
content
JObject
JObject representing the body of the document
id
string

(null)
Document ID. Will use an auto-generated ID if not specified
waitForRefresh
bool

(false)
If true, waits for the change to be reflected for search (up to 1s)

Return #

A JObject containing the document creation result.

PropertyTypeDescription
_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 created in case of success

Exceptions #

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

Usage #

try {
  JObject result = await kuzzle.Document.CreateAsync(
    "nyc-open-data",
    "yellow-taxi",
    JObject.Parse(@"{
      ""lastname"": ""Eggins""
    }"),
    id: "some-id");
  Console.WriteLine(result.ToString());
  /*
  {
    "_index": "nyc-open-data",
    "_type": "yellow-taxi",
    "_id": "some-id",
    "_version": 1,
    "result": "created",
    "created": true,
    "_source": {
      "lastName": "Eggins",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1537445737667,
        "updatedAt": null,
        "updater": null,
        "active": true,
        "deletedAt": null
      }
    }
  }
  */
  Console.WriteLine("Document successfully created");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}