You are currently browsing legacy 3.5 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Querying: How to stream query results?

Query results can be streamed using stream method from advanced() session operations.


public <T> CloseableIterator<StreamResult<T>> stream(IRavenQueryable<T> query);

public <T> CloseableIterator<StreamResult<T>> stream(IRavenQueryable<T> query, Reference<QueryHeaderInformation> queryHeaderInformation);

public <T> CloseableIterator<StreamResult<T>> stream(IDocumentQuery<T> query);

public <T> CloseableIterator<StreamResult<T>> stream(IDocumentQuery<T> query, Reference<QueryHeaderInformation> queryHeaderInformation);
query IQueryable or IDocumentQuery Query to stream results for.
queryHeaderInformation QueryHeaderInformation Information about performed query.
Return Value
CloseableIterator<StreamResult<T>> Iterator with entities.
QueryHeaderInformation Information about performed query.

Example I

QEmployee e = QEmployee.employee;
IRavenQueryable<Employee> query = session

try (CloseableIterator<StreamResult<Employee>> results = session.advanced().stream(query)) {
  while (results.hasNext()) {
    StreamResult<Employee> employee =;

Example II

QEmployee e = QEmployee.employee;
IDocumentQuery<Employee> query = session
  .whereEquals(e.firstName, "Robert");

Reference<QueryHeaderInformation> queryHeaderInfoRef = new Reference<>();
try (CloseableIterator<StreamResult<Employee>> results = session.advanced().stream(query, queryHeaderInfoRef)) {
  while (results.hasNext()) {
    StreamResult<Employee> employee =;