You are currently browsing legacy 3.0 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 get query statistics?

Query statistics can provide important information about query e.g. duration, total number of results, staleness information, etc. To access statistics use statistics method.

Syntax

IRavenQueryable<TResult> statistics(Reference<RavenQueryStatistics> stats);
Parameters
stats RavenQueryStatistics Statistics for query.
Return Value
RavenQueryStatistics Statistics for query.

Example

Reference<RavenQueryStatistics> statsRef = new Reference<>();
QEmployee e = QEmployee.employee;
List<Employee> employees = session
  .query(Employee.class)
  .where(e.firstName.eq("Robert"))
  .statistics(statsRef)
  .toList();

int totalResults = statsRef.value.getTotalResults();
long durationMiliseconds = statsRef.value.getDurationMiliseconds();