Commands Overview
-
RavenDB's Client API is structured in layers.
At the highest layer, you interact with the document store and the document session,
which handle most common database tasks like loading, saving, and querying documents. -
Beneath this high-level interface are Operations and Commands:
-
Operations:
-
Operations provide management functionality outside the session's context,
like creating a database, performing bulk actions, or managing server-wide configurations. -
Learn more about Operations in what are Operations.
-
-
Commands:
-
All high-level methods and Operations are built on top of Commands.
Commands form the lowest-level operations that directly communicate with the server. -
For example, a session’s Load method translates internally to a LoadOperation,
which ultimately relies on a GetDocumentsCommand to fetch data from the server. -
Commands are responsible for sending the appropriate request to the server using a
Request Executor
,
and parsing the server's response. -
All commands can be executed using either the Store's Request Executor or the Session's Request Executor,
regardless of whether the command is session-related or not.
-
-
-
This layered structure lets you work at any level, depending on your needs.
-
In this page:
Execute command - using the Store Request Executor
This example shows how to execute the low-level CreateSubscriptionCommand
via the Store.
(For examples of creating a subscription using higher-level methods, see subscription creation examples).
// Define a command
const cmd = new CreateSubscriptionCommand({
name: "Orders subscription",
query: "from Orders"
});
// Call 'execute' on the store's Request Executor to run the command on the server
// Pass the command
await documentStore.getRequestExecutor().execute(cmd);
Execute command - using the Session Request Executor
This example shows how to execute the low-level GetDocumentsCommand
via the Session.
(For loading a document using higher-level methods, see loading entities).
const session = documentStore.openSession();
// Define a command
const cmd = new GetDocumentsCommand(
{ conventions: documentStore.conventions, id: "orders/1-A" });
// Call 'execute' on the session's Request Executor to run the command on the server
// Pass the command
await session.advanced.requestExecutor.execute(cmd);
// Access the results
const order = command.result.results[0];
const orderedAt = order.OrderedAt;
-
Note that the transaction created for the HTTP request when executing the command
is separate from the transaction initiated by the session's SaveChanges method,
even if both are called within the same code block. -
Learn more about transactions in RavenDB in Transaction support.
Available commands
-
The Following low-level commands are available:
- ConditionalGetDocumentsCommand
- CreateSubscriptionCommand
- DeleteDocumentCommand
- DeleteSubscriptionCommand
- DropSubscriptionConnectionCommand
- ExplainQueryCommand
- GetClusterTopologyCommand
- GetConflictsCommand
- GetDatabaseTopologyCommand
- GetDocumentsCommand
- GetIdentitiesCommand
- GetNextOperationIdCommand
- GetNodeInfoCommand
- GetOperationStateCommand
- GetRawStreamResultCommand
- GetRevisionsBinEntryCommand
- GetRevisionsCommand
- GetSubscriptionsCommand
- GetSubscriptionStateCommand
- GetTcpInfoCommand
- GetTrafficWatchConfigurationCommand
- HeadAttachmentCommand
- HeadDocumentCommand
- HiLoReturnCommand
- IsDatabaseLoadedCommand
- KillOperationCommand
- MultiGetCommand
- NextHiLoCommand
- NextIdentityForCommand
- PutDocumentCommand
- PutSecretKeyCommand
- QueryCommand
- QueryStreamCommand
- SeedIdentityForCommand
- SingleNodeBatchCommand
- WaitForRaftIndexCommand
Syntax
execute(command);
execute(command, sessionInfo);
execute(command, sessionInfo, executeOptions);