Commands: Documents: Put


Put is used to insert or update a document in a database.

In this page:

Syntax

public PutDocumentCommand(string id, string changeVector, BlittableJsonReaderObject document)
Parameters Type Description
conventions DocumentConventions Document conventions
id string Unique ID under which document will be stored
changeVector string Entity changeVector, used for concurrency checks (null to skip check)
document BlittableJsonReaderObject The document to store. You may use session.Advanced.JsonConverter.ToBlittable(doc, docInfo); to convert your entity to a BlittableJsonReaderObject.

Example

// Create a new document
var doc = new Category
{
    Name = "My category",
    Description = "My category description"
};
// Create metadata on the document
var docInfo = new DocumentInfo
{
    Collection = "Categories"
};
// Convert your entity to a BlittableJsonReaderObject
var blittableDoc = session.Advanced.JsonConverter.ToBlittable(doc, docInfo);

// The Put command (parameters are document ID, changeVector check is null, the document to store)
var command = new PutDocumentCommand("categories/999", null, blittableDoc);
// RequestExecutor sends the command to the server
session.Advanced.RequestExecutor.Execute(command, session.Advanced.Context);