Session: How to Perform Operations Lazily

Operation execution for operations such as load, load with includes, loadStartingWith and queries can be deferred till needed using lazy session operations. Those operations can be accessed using lazily() property found in advanced session operations.


Available operations are:

  • load - described here.
  • load with includes - described here.
  • loadStartingWith - described here.


Dedicated article about lazy queries can be found here.


const employeeLazy = session

const employee = await employeeLazy.getValue(); // load operation will be executed here

Executing All Pending Lazy Operations

To execute all pending lazy operations use executeAllPendingLazyOperations() method from eager session operations found under eagerly property in advanced session operations.

const employeesLazy = session
    .query({ collection: "Employees" })

await session.advanced.eagerly.executeAllPendingLazyOperations(); // query will be executed here

const employees = await employeesLazy.getValue();