---
title: "What is a DocumentQuery?"
description: "Use DocumentQuery in RavenDB for a lower-level, chainable query API that provides more control than the standard LINQ-based Query."
url: "https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query"
version: "7.2"
language: "java"
---

# What is a DocumentQuery?

> Client language: Java. Also available for [C#](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.md), [Python](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.python.md), [PHP](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.php.md), [Node.js](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.nodejs.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."

Querying capabilities can be accessed via the `documentQuery` method in advanced session operations.  
`DocumentQuery` gives you more flexibility and control over the process of building a query.

## Syntax

```java
<T> IDocumentQuery<T> documentQuery(Class<T> clazz);

<T> IDocumentQuery<T> documentQuery(Class<T> clazz, String indexName, String collectionName, boolean isMapReduce);
```

| Parameter | Type | Description |
| - | - | - |
| **indexName** | `String` | Name of an index to perform a query on<br /> (mutually exclusive with **collectionName**) |
| **collectionName** | `String` | Name of a collection to perform a query on<br /> (mutually exclusive with **indexName**) |
| **isMapReduce** | `bool` | Indicates if a queried index is a map-reduce index<br /> (modifies how we treat identifier properties) |

| Return Value | |
| - | - |
| **IDocumentQuery** | Instance implementing IDocumentQuery interface containing additional query methods and extensions |

## Example I - Basic

```java
// load all entities from 'Employees' collection
List<Employee> employees = session
    .advanced()
    .documentQuery(Employee.class)
    .toList();
```

```java
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
List<Employee> employees = session
    .advanced()
    .documentQuery(Employee.class)
    .whereEquals("FirstName", "Robert")
    .toList();
```

## Example II - Querying Specified Index

```java
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'My/Custom/Index'
List<Employee> employees = session
    .advanced()
    .documentQuery(Employee.class, "My/Custom/Index", null, false)
    .whereEquals("FirstName", "Robert")
    .toList();
```

or

```java
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'My/Custom/Index'
List<Employee> employees = session
    .advanced()
    .documentQuery(Employee.class, MyCustomIndex.class)
    .whereEquals("FirstName", "Robert")
    .toList();
```

## Custom Methods and Extensions

> **Note**
>
> Functionality of most of the methods match the functionality of their `query` counterparts and therefore will not be described again.
> Please refer to the appropriate counterpart documentation articles. Links starting with `[query]` are marking those articles.

Available methods:

- addAfterQueryExecutedListener
- addBeforeQueryExecutedListener
- addOrder
- addParameter
- \[Query] [aggregateBy](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-a-faceted-search.java.md)
- \[Query] [aggregateUsing](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-a-faceted-search.java.md)
- andAlso
- boost
- closeSubclause
- containsAll
- containsAny
- count
- countLazily
- distinct
- first
- firstOrDefault
- fuzzy
- [groupBy](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-group-by-query.java.md)
- [groupByArrayValues](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-group-by-query.java.md#by-array-values)
- [groupByArrayContent](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-group-by-query.java.md#by-array-content)
- include
- intersect
- invokeAfterQueryExecuted
- invokeAfterStreamExecuted
- \[Query] [lazily](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-perform-queries-lazily.java.md)
- moreLikeThis
- negateNext
- \[Query] [noCaching](https://docs.ravendb.net/7.2/querying/customize-query.java.md#nocaching)
- [not](https://docs.ravendb.net/7.2/querying/filtering-query-results/use-logical-operators.java.md#negate-a-condition-with-not)
- \[Query] [noTracking](https://docs.ravendb.net/7.2/querying/customize-query.java.md#notracking)
- ofType
- openSubclause
- orderBy
- orderByDescending
- \[Query] [orderByDistance](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-make-a-spatial-query.java.md#orderbydistance)
- \[Query] [orderByDistanceDescending](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-make-a-spatial-query.java.md#orderbydistancedescending)
- orderByScore
- orderByScoreDescending
- orElse
- proximity
- randomOrdering
- \[Query] [relatesToShape](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-make-a-spatial-query.java.md#example-ii)
- search
- selectFields
- single
- singleOrDefault
- skip
- \[Query] [spatial](https://docs.ravendb.net/7.2/client-api/session/querying/how-to-make-a-spatial-query.java.md#spatial)
- statistics
- suggestUsing
- take
- usingDefaultOperator
- \[Query] [waitForNonStaleResults](https://docs.ravendb.net/7.2/querying/customize-query.java.md#waitfornonstaleresults)
- \[Query] [waitForNonStaleResultsAsOf](https://docs.ravendb.net/7.2/querying/customize-query.java.md#waitfornonstaleresultsasof)
- where
- whereBetween
- whereEndsWith
- whereEquals
- [whereExists](https://docs.ravendb.net/7.2/querying/filtering-query-results/filter-by-field-presence.java.md)
- whereGreaterThan
- whereGreaterThanOrEqual
- whereIn
- whereLessThan
- whereLessThanOrEqual
- [whereLucene](https://docs.ravendb.net/7.2/querying/filtering-query-results/filter-with-lucene-syntax.java.md)
- whereNotEquals
- [whereRegex](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex.java.md)
- whereStartsWith
- withinRadiusOf

## Remarks

By default, if the `page size` is not specified, all of the matching records will be retrieved from a database.

## See also

- [Query overview](https://docs.ravendb.net/7.2/querying/overview.md)
- [Filter with Lucene Syntax](https://docs.ravendb.net/7.2/querying/filtering-query-results/filter-with-lucene-syntax.java.md)
- [Querying: Basics](https://docs.ravendb.net/7.2/indexes/querying/query-index.java.md)
- [Query vs DocumentQuery](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query.java.md)
- [Projections](https://docs.ravendb.net/7.2/indexes/querying/projections.java.md)
