---
title: "Stream Time Series Data"
description: "Stream large RavenDB time series query results to process entries one at a time without loading the entire result set into memory."
url: "https://docs.ravendb.net/7.2/document-extensions/timeseries/querying/stream-timeseries"
version: "7.2"
language: "csharp"
---

# Stream Time Series Data

> Client language: C#. Also available for [Java](https://docs.ravendb.net/7.2/document-extensions/timeseries/querying/stream-timeseries.java.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - This page explains how time series data can be streamed:
>   1. Stream a time series directly.
>   2. Stream time series query results.
>
> - In this page:
>   - [Syntax](#syntax)
>   - [Examples](#examples)

## Syntax

### Stream a time series directly:

Get a time series (e.g. [using `TimeSeriesFor.Get`](https://docs.ravendb.net/7.2/document-extensions/timeseries/client-api/session/get/get-entries.md)),
and call `Stream()`/`StreamAsync()`.

```csharp
IEnumerator<T> Stream(DateTime? from = null, DateTime? to = null, TimeSpan? offset = null);

Task<IAsyncEnumerator<T>> StreamAsync(DateTime? from = null, DateTime? to = null, TimeSpan? offset = null);
```

| Parameters | Type | Description |
| - | - | - |
| **from** | `DateTime?` | Start the stream from a certain time. If null, stream starts from the beginning of the time series. |
| **to** | `DateTime?` | Stop the stream at a certain time. If null, stream stops at the end of the time series. |
| **offset** | `TimeSpan?` | Change the timestamp of the streamed time series entries by adding this amount of time. |

### Stream results of time series queries:

This syntax is the same as the syntax for streaming query results in general,
found [here](https://docs.ravendb.net/7.2/querying/stream-query-results.md).

```csharp
IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IQueryable<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IQueryable<T> query,
  out StreamQueryStatistics streamQueryStats);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IDocumentQuery<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IRawDocumentQuery<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IRawDocumentQuery<T> query,
  out StreamQueryStatistics streamQueryStats);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
  IDocumentQuery<T> query,
  out StreamQueryStatistics streamQueryStats);
```

| Parameters | Type | Description |
| - | - | - |
| **query** | [IQueryable](https://docs.ravendb.net/7.2/querying/overview.md#sessionquery), [IDocumentQuery](https://docs.ravendb.net/7.2/querying/overview.md#sessionadvanceddocumentquery) or [IRawDocumentQuery](https://docs.ravendb.net/7.2/querying/overview.md#sessionadvancedrawquery) | Query to stream results for. |
| **streamQueryStats** | `out` [StreamQueryStatistics](https://docs.ravendb.net/7.2/glossary/stream-query-statistics.md) | Information about performed query. |

| Return Value | Description |
| - | - |
| IEnumerator<[StreamResult](https://docs.ravendb.net/7.2/glossary/stream-result.md)> | Enumerator with entities. |

## Examples

### Example I

Using `TimeSeriesFor`:

#### Sync

```csharp
var timeseries = session.TimeSeriesFor<HeartRate>("user/1-A");
var results = new List<TimeSeriesEntry>();

using (var TSstream = timeseries.Stream())
{
  while (TSstream.MoveNext())
  {
      results.Add(TSstream.Current);
  }
}
```

#### Async

```csharp
var timeseries = session.TimeSeriesFor<HeartRate>("user/1-A");
var results = new List<TimeSeriesEntry>();
var TSstream = await timeseries.StreamAsync();

await using (TSstream)
{
  while (await TSstream.MoveNextAsync())
  {
      results.Add(TSstream.Current);
  }
}
```

### Example II

Using a `RawQuery`:

#### Sync

```csharp
var query = session.Advanced.RawQuery<TimeSeriesRawResult>(@"
  from Users
  select timeseries (
      from HeartRate
  )");

var results = new List<TimeSeriesEntry>();

using (var docStream = session.Advanced.Stream(query))
{
  while (docStream.MoveNext())
  {
      var document = docStream.Current.Result;
      var timeseries = document.Stream;
      while (timeseries.MoveNext())
      {
          results.Add(timeseries.Current);
      }
  }
}
```

#### Async

```csharp
var query = session.Advanced.AsyncRawQuery<TimeSeriesRawResult>(@"
  from Users
  select timeseries (
      from HeartRate
  )");

var results = new List<TimeSeriesEntry>();

await using (var docStream = await session.Advanced.StreamAsync(query))
{
  while (await docStream.MoveNextAsync())
  {
      var document = docStream.Current.Result;
      var timeseries = document.StreamAsync;
      while (await timeseries.MoveNextAsync())
      {
          results.Add(timeseries.Current);
      }
  }
}
```

## See also

- [Time Series Overview](https://docs.ravendb.net/7.2/document-extensions/timeseries/overview.md)
- [Range Selection](https://docs.ravendb.net/7.2/document-extensions/timeseries/querying/choosing-query-range.md)
- [Filtering](https://docs.ravendb.net/7.2/document-extensions/timeseries/querying/filtering.md)
- [Aggregation and Projection](https://docs.ravendb.net/7.2/document-extensions/timeseries/querying/aggregation-and-projections.md)
- [Get Time Series Entries](https://docs.ravendb.net/7.2/document-extensions/timeseries/client-api/session/get/get-entries.md)
- [How To Stream Query Results](https://docs.ravendb.net/7.2/querying/stream-query-results.md)
