What are Operations



Why use operations

  • Operations provide management functionality that is Not available in the context of the session, e.g.:
    create/delete a database, execute administrative tasks, assign permissions, change server configuration, etc.

  • Some operations (e.g. PatchOperation) can also be carried out via the session (e.g. session.advanced.patch()).
    However, while a session wraps multiple actions into a single business transaction,
    the operation is an individual action that is Not part of the session transaction.

How operations work

  • Sending the request:
    Each Operation creates an HTTP request message to be sent to the relevant server endpoint.
    The DocumentStore OperationExecutor sends the request and processes the results.
  • Target node:
    By default, the operation will be executed on the server node that is defined by the client configuration.
    However, server-maintenance operations can be executed on a specific node by using the forNode method.
  • Target database:
    By default, operations work on the default database defined in the DocumentStore.
    However, common operations & maintenance operations can operate on a different database by using the forDatabase method.
  • Transaction scope:
    Operations execute as a single-node transaction.
    If needed, data will then replicate to the other nodes in the database-group.
  • Background operations:
    Some operations may take a long time to complete and can be awaited for completion.
    Learn more below.

Common operations

  • All common operations implement the IOperation interface.
    The operation is executed within the database scope.
    Use forDatabase to operate on a specific database other than the default defined in the store.

  • These operations include set-based operations such as PatchOperation, CounterBatchOperation,
    document-extensions related operations such as getting/putting an attachment, and more.
    See all available operations below.

  • To execute a common operation request,
    use the send method on the operations property in the DocumentStore.

Example:

// Define operation, e.g. get all counters info for a document
const getCountersOp = new GetCountersOperation("products/1-A");

// Execute the operation by passing the operation to operations.send
const allCountersResult = await documentStore.operations.send(getCountersOp);

// Access the operation result
const numberOfCounters = allCountersResult.counters.length;

Send syntax:

// Available overloads:
await send(operation);
await send(operation, sessionInfo);
await send(operation, sessionInfo, documentType);

await send(patchOperaton);
await send(patchOperation, sessionInfo);
await send(patchOperation, sessionInfo, resultType);

The following common operations are available:


Maintenance operations

  • All maintenance operations implement the IMaintenanceOperation interface.
    The operation is executed within the database scope.
    Use forDatabase to operate on a specific database other than the default defined in the store.

  • These operations include database management operations such as setting client configuration,
    managing indexes & ongoing-tasks operations, getting stats, and more.
    See all available maintenance operations below.

  • To execute a maintenance operation request,
    use the send method on the maintenance property in the DocumentStore.

Example:

// Define operation, e.g. stop an index 
const stopIndexOp = new StopIndexOperation("Orders/ByCompany");

// Execute the operation by passing the operation to maintenance.send
await documentStore.maintenance.send(stopIndexOp);

// This specific operation returns void
// You can send another operation to verify the index running status
const indexStatsOp = new GetIndexStatisticsOperation("Orders/ByCompany");
const indexStats = await documentStore.maintenance.send(indexStatsOp);
const status = indexStats.status; // will be "Paused"

Send syntax:

await send(operation);

The following maintenance operations are available:


  • Statistics:
           GetStatisticsOperation
           GetDetailedStatisticsOperation
           GetCollectionStatisticsOperation
           GetDetailedCollectionStatisticsOperation

  • Client Configuration:
           PutClientConfigurationOperation
           GetClientConfigurationOperation

  • Indexes:
           PutIndexesOperation
           SetIndexesLockOperation
           SetIndexesPriorityOperation
           GetIndexErrorsOperation
           GetIndexOperation
           GetIndexesOperation
           GetTermsOperation
           GetIndexPerformanceStatisticsOperation
           GetIndexStatisticsOperation
           GetIndexesStatisticsOperation
           GetIndexingStatusOperation
           GetIndexStalenessOperation
           GetIndexNamesOperation
           StartIndexOperation
           StartIndexingOperation
           StopIndexOperation
           StopIndexingOperation
           ResetIndexOperation
           DeleteIndexOperation
           DeleteIndexErrorsOperation
           DisableIndexOperation
           EnableIndexOperation
           IndexHasChangedOperation

  • Analyzers:
           PutAnalyzersOperation
           DeleteAnalyzerOperation

  • Ongoing tasks:
           GetOngoingTaskInfoOperation
           DeleteOngoingTaskOperation
           ToggleOngoingTaskStateOperation

  • ETL tasks:
           AddEtlOperation
           UpdateEtlOperation
           ResetEtlOperation

  • Replication tasks:
           PutPullReplicationAsHubOperation
           GetPullReplicationTasksInfoOperation
           GetReplicationHubAccessOperation
           GetReplicationPerformanceStatisticsOperation
           RegisterReplicationHubAccessOperation
           UnregisterReplicationHubAccessOperation
           UpdateExternalReplicationOperation
           UpdatePullReplicationAsSinkOperation

  • Backup:
           BackupOperation
           GetPeriodicBackupStatusOperation
           StartBackupOperation
           UpdatePeriodicBackupOperation

  • Connection strings:
           PutConnectionStringOperation
           RemoveConnectionStringOperation

  • Transaction recording:
           StartTransactionsRecordingOperation
           StopTransactionsRecordingOperation
           ReplayTransactionsRecordingOperation

  • Database settings:
           PutDatabaseSettingsOperation
           GetDatabaseSettingsOperation

  • Identities:
           GetIdentitiesOperation
           NextIdentityForOperation
           SeedIdentityForOperation

  • Time series:
           ConfigureTimeSeriesOperation
           ConfigureTimeSeriesPolicyOperation
           ConfigureTimeSeriesValueNamesOperation
           RemoveTimeSeriesPolicyOperation

  • Revisions:
           ConfigureRevisionsOperation

  • Sorters:
           PutSortersOperation
           DeleteSorterOperation

  • Misc:
           ConfigureExpirationOperation
           ConfigureRefreshOperation
           UpdateDocumentsCompressionConfigurationOperation
           DatabaseHealthCheckOperation
           GetOperationStateOperation
           CreateSampleDataOperation

Server-maintenance operations

  • All server-maintenance operations implement the IServerOperation interface.
    The operation is executed within the server scope.
    Use forNode to operate on a specific node other than the default defined in the client configuration.

  • These operations include server management and configuration operations.
    See all available operations below.

  • To execute a server-maintenance operation request,
    use the send method on the maintenance.server property in the DocumentStore.

Example:

// Define operation, e.g. get the server build number
const getBuildNumberOp = new GetBuildNumberOperation();

// Execute the operation by passing the operation to maintenance.server.send
const buildNumberResult = await documentStore.maintenance.server.send(getBuildNumberOp);

// Access the operation result
const version = buildNumberResult.buildVersion;

Send syntax:

await send(operation);

The following server-maintenance operations are available:


  • Client certificates:
           PutClientCertificateOperation
           CreateClientCertificateOperation
           GetCertificatesOperation
           DeleteCertificateOperation
           EditClientCertificateOperation
           GetCertificateMetadataOperation
           ReplaceClusterCertificateOperation

  • Server-wide client configuration:
           PutServerWideClientConfigurationOperation
           GetServerWideClientConfigurationOperation

  • Database management:
           CreateDatabaseOperation
           DeleteDatabasesOperation
           ToggleDatabasesStateOperation
           GetDatabaseNamesOperation
           AddDatabaseNodeOperation
           PromoteDatabaseNodeOperation
           ReorderDatabaseMembersOperation
           CompactDatabaseOperation
           GetDatabaseRecordOperation
           SetDatabasesLockOperation
           CreateDatabaseOperationWithoutNameValidation
           SetDatabaseDynamicDistributionOperation
           ModifyDatabaseTopologyOperation
           UpdateDatabaseOperation
           UpdateUnusedDatabasesOperation

  • Server-wide ongoing tasks:
           DeleteServerWideTaskOperation
           ToggleServerWideTaskStateOperation

  • Server-wide replication tasks:
           PutServerWideExternalReplicationOperation
           GetServerWideExternalReplicationOperation
           GetServerWideExternalReplicationsOperation

  • Server-wide backup tasks:
           PutServerWideBackupConfigurationOperation
           GetServerWideBackupConfigurationOperation
           GetServerWideBackupConfigurationsOperation
           RestoreBackupOperation

  • Server-wide analyzers:
           PutServerWideAnalyzersOperation
           DeleteServerWideAnalyzerOperation

  • Server-wide sorters:
           PutServerWideSortersOperation
           DeleteServerWideSorterOperation

  • Logs & debug:
           SetLogsConfigurationOperation
           GetLogsConfigurationOperation
           GetClusterDebugInfoPackageOperation
           GetBuildNumberOperation
           GetServerWideOperationStateOperation

  • Traffic watch:
           PutTrafficWatchConfigurationOperation
           GetTrafficWatchConfigurationOperation

  • Revisions:
           ConfigureRevisionsForConflictsOperation

  • Misc:
           ModifyConflictSolverOperation
           OfflineMigrationOperation

Wait for completion

  • Some operations may take a long time to complete.
    Those operations will run in the server background and can be awaited for completion.
  • Those operations implement an interface with result type OperationIdResult.
  • For those operations, the send method returns a promise for an object that can be awaited on that Id.

Example:

// Define operation, e.g. delete all discontinued products 
// Note: This operation implements: 'IOperation<OperationIdResult>'
const deleteByQueryOp = new DeleteByQueryOperation("from Products where Discontinued = true");

// Execute the operation
// 'send' returns an object that can be awaited on
const asyncOperation = await documentStore.operations.send(deleteByQueryOp);

// Call method 'waitForCompletion' to wait for operation completion 
await asyncOperation.waitForCompletion();

Syntax:

await waitForCompletion();