Language
C#
Article For
3.5 4.0 4.1 4.2 5.0 5.1 5.2 5.3

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();