Delete Compare Exchange Operation
-
Use
DeleteCompareExchangeValueOperation
to delete a compare-exchange item. -
The compare-exchange item is only deleted if the index in the request is equal to the current index
stored on the server for the specified key. -
Compare-exchange items can also be deleted via advanced session methods, or from the Studio.
-
In this page:
Delete compare exchange item
// Get an existing compare-exchange item
const getCmpXchgOp = new GetCompareExchangeValueOperation("johnDoe@gmail.com");
const itemResult = await documentStore.operations.send(getCmpXchgOp);
// Keep the item's version
const versionOfItem = itemResult.index;
// Delete the compare-exchange item:
// =================================
// Define the delete compare-exchange operation, pass:
// * The item's KEY
// * The item's INDEX (its version)
// The compare-exchange item will only be deleted if this number
// is equal to the one stored on the server when the delete operation is executed.
const deleteCmpXchgOp = new DeleteCompareExchangeValueOperation("johnDoe@gmail.com", versionOfItem);
// Execute the operation by passing it to operations.send
const deleteResult = await documentStore.operations.send(deleteCmpXchgOp);
// Verify delete results:
assert.ok(deleteResult.successful);
Syntax
const deleteCmpXchgOp = new DeleteCompareExchangeValueOperation(key, index, clazz?);
Parameter | Type | Description |
---|---|---|
key | string | The key of the item to be deleted |
index | number | The version number of the item to be deleted |
clazz | object | When the item's value is a class, you can specify its type in this parameter |
// Return value of store.operations.send(deleteCmpXchgOp)
// ======================================================
class CompareExchangeResult {
successful;
value;
index;
}
Return Value | |||
---|---|---|---|
successful | boolean |
|
|
value | object |
|
|
index | number |
|