Include Time Series with query


  • When querying via session.query for documents that contain time series,
    you can request to include their time series data in the server response.

  • 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 making a query

In this example, we retrieve a document using session.query
and include entries from the document's "HeartRates" time series.

// Query for a document and include a whole time-series
const user = await session.query({ collection: "users" })
    .whereEquals("name", "John")
     // Call 'includeTimeSeries' to include the time series entries in the response
     // Pass the time series name
     // (find more include builder overloads under the Syntax section)
    .include(includeBuilder => includeBuilder.includeTimeSeries("HeartRates"))
    .first();

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(user, "HeartRates")
    .get();

const entryValue = entries[0].value;

const numberOfRequests2 = session.advanced.numberOfRequests;
assert.equal(numberOfRequests1, numberOfRequests2);
from "users"
where name = "John" 
include timeseries("HeartRates", null, null)
limit null, 1

Syntax

include 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.