Delete Document Command
-
Use the low-level
DeleteDocumentCommand
to remove a document from the database. -
To delete a document using a higher-level method, see deleting entities.
-
In this page:
Examples
Delete document command - using the Store's request executor:
// Define the Delete Command
// Pass the document ID & whether to make a concurrency check
const command = new DeleteDocumentCommand("employees/1-A", null);
// Send the command to the server using the Store's Request Executor
await documentStore.getRequestExecutor().execute(command);
Delete document command - using the Session's request executor:
const command = new DeleteDocumentCommand("employees/1-A", null);
// Send the command to the server using the Session's Request Executor
await session.advanced.requestExecutor.execute(command);
Delete document command - with concurrency check:
// Load a document
const employeeDocument = await session.load('employees/2-A');
const cv = session.advanced.getChangeVectorFor(employeeDocument);
// Modify the document content and save changes
// The change-vector of the stored document will change
employeeDocument.Title = "Some new title";
await session.saveChanges();
try {
// Try to delete the document with the previous change-vector
const command = new DeleteDocumentCommand("employees/2-A", cv);
await session.advanced.requestExecutor.execute(command);
}
catch (err) {
// A concurrency exception is thrown
// since the change-vector of the document in the database
// does not match the change-vector specified in the delete command
assert.equal(err.name, "ConcurrencyException");
}
Syntax
DeleteDocumentCommand(id, changeVector);
Parameter | Type | Description |
---|---|---|
id | string |
The ID of the document to delete. |
changeVector | string |
The change-vector of the document you wish to delete, used for optimistic concurrency control. Pass null to skip the check and force the deletion. |