Language
C# Java

Session: How to Defer Operations

Operations can be deferred till saveChanges() is called by using defer() method in advanced session operations. There are three types of commands that can be deferred:

  • PutCommandData
  • DeleteCommandData
  • DeletePrefixedCommandData
  • PatchCommandData
  • PutAttachmentCommandData
  • DeleteAttachmentCommandData

Syntax

session.advanced.defer(...commands);
Parameters
commands ICommandData[] Command objects implementing ICommandData interface.

Example

const value1 = {
    "name": "My Product",
    "supplier": "suppliers/999-A",
    "@metadata": {
        "@collection": "Users"
    }
};

const putCommand1 =
    new PutCommandDataWithJson("products/999-A",
        null,
        value1);

const value2 = {
    "name": "My Product",
    "supplier": "suppliers/999-A",
    "@metadata": {
        "@collection": "Suppliers"
    }
};

const putCommand2 =
    new PutCommandDataWithJson("suppliers/999-A",
        null,
        value2);

const command3 = new DeleteCommandData("products/1-A", null);

session.advanced.defer(putCommand1, putCommand2, command3);