Operations: What are the Operations

The RavenDB client API is built with the notion of layers. At the top, and what you will usually interact with, are the DocumentStore and the DocumentSession.

They in turn, are built on top of the notion of Operations and Commands.

Operations are an encapsulation of a set of low level commands which are used to manipulate data, execute administrative tasks, and change the configuration on a server.

They are available in the DocumentStore under the operations, maintenance, and maintenance().server methods.

Common Operations

Common operations include set based operations for Patching or removal of documents by using queries (more can be read here).
There is also the ability to handle distributed Compare Exchange operations and manage Attachments and Counters.

How to Send an Operation

In order to excecute an operation, you will need to use the send or sendAsync methods. Avaliable overloads are:

public void send(IVoidOperation operation)

public void send(IVoidOperation operation, SessionInfo sessionInfo)

public <TResult> TResult send(IOperation<TResult> operation)

public <TResult> TResult send(IOperation<TResult> operation, SessionInfo sessionInfo)

public PatchStatus send(PatchOperation operation, SessionInfo sessionInfo)

public <TEntity> PatchOperation.Result<TEntity> send(Class<TEntity> entityClass, PatchOperation operation, SessionInfo sessionInfo)
public Operation sendAsync(IOperation<OperationIdResult> operation)

public Operation sendAsync(IOperation<OperationIdResult> operation, SessionInfo sessionInfo)

The following operations are available:

Compare Exchange





Example - Get Attachment

try (CloseableAttachmentResult fetchedAttachment = store
    .send(new GetAttachmentOperation("users/1", "file.txt", AttachmentType.DOCUMENT, null))) {
    // do stuff with the attachment stream --> fetchedAttachment.data

Maintenance Operations

Maintenance operations include operations for changing the configuration at runtime and for management of index operations.

How to Send an Operation

public void send(IVoidMaintenanceOperation operation)

public <TResult> TResult send(IMaintenanceOperation<TResult> operation)

The following maintenance operations are available:

Client Configuration



Example - Stop Index

store.maintenance().send(new StopIndexOperation("Orders/ByCompany"));

Server Operations

These type of operations contain various administrative and miscellaneous configuration operations.

How to Send an Operation

public void send(IVoidServerOperation operation)

public <TResult> TResult send(IServerOperation<TResult> operation)
public Operation sendAsync(IServerOperation<OperationIdResult> operation)

The following server-wide operations are available:

Cluster Management


Example - Get Build Number

GetClientConfigurationOperation.Result result
    = store.maintenance().send(new GetClientConfigurationOperation());



By default, operations available in store.operations or store.maintenance are working on a default database that was setup for that store. To switch operations to a different database that is available on that server use the forDatabase method.