Include Time Series with load


  • When loading a document via session.load,
    you can include all entries of a time series or a specific range of entries.

  • The included time series data is stored within the session
    and can be provided instantly when requested without any additional server calls.

  • In this page:


Include time series when loading a document

In this example, we load a document using session.load,
and include a selected range of entries from time series "HeartRates".

const session = documentStore.openSession();

const baseTime = new Date();
const from = new Date(baseTime.getTime() + 60_000 * 3);
const to = new Date(baseTime.getTime() + 60_000 * 8);

// Load a document entity to the session
const user = await session.load("users/john", {
    // Call 'includeTimeSeries' to include time series entries, pass:
    // * The time series name
    // * Start and end timestamps indicating the range of entries to include
    includes: builder => builder.includeTimeSeries("HeartRates", from, to)
});

const numberOfRequests1 = session.advanced.numberOfRequests;

// The following call to 'get' will Not trigger a server request,  
// the entries will be retrieved from the session's cache.  
const entries = await session
    .timeSeriesFor("users/john", "HeartRates")
    .get(from, to);

const numberOfRequests2 = session.advanced.numberOfRequests;
assert.equal(numberOfRequests1, numberOfRequests2);

Syntax

session.load

load(id, options?);
Parameter Type Description
id string Document ID to load.
options object object containing the includes builder that specifies which time series entries to include.

includes builder methods:

includeTimeSeries(name);
includeTimeSeries(name, from, to);
Parameter Type Description
name string Time series name.
from Date Time series range start (inclusive).
Default: minimum date value.
to Date Time series range end (inclusive).
Default: maximum date value.