---
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: "php"
---

# What is a DocumentQuery?

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

> **Note**
>
> - RavenDB queries can be executed via `query`, `documentQuery` or directly using raw `RQL`.  
>   Learn more in [Query Overview](https://docs.ravendb.net/7.2/querying/overview.php.md).
>
> - Unlike the **C#** client (where the `Query` method supports LINQ while `DocumentQuery` provides lower-level flexibility and control),
>   the **PHP** client API implements the `query` and `document_query` methods with **identical functionality**.
>
>   See [query -vs- documentQuery](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query.php.md) for additional details.
>
> - In this article:
>   - [`documentQuery` examples](#documentquery-examples)
>   - [Syntax](#syntax)

## documentQuery examples {#documentquery-examples}

#### Query collection - no filtering

##### documentQuery

```php
// load all entities from 'Employees' collection
$employees = $session
    ->advanced()
    ->documentQuery(Employee::class)
    ->toList();
```

##### RQL

```sql
from "Employees"
```

#### Query collection - with filtering

##### documentQuery

```php
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
$employees = $session
    ->advanced()
    ->documentQuery(Employee::class)
    ->whereEquals("FirstName", "Robert")
    ->toList();
```

##### RQL

```sql
from "Employees" where FirstName == "Robert"
```

#### Query an index

- Using a Path string

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

- Using an index Class

```php
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'MyCustomIndex::class'
$employees = $session
    ->advanced()
    ->documentQuery(Employee::class, MyCustomIndex::class)
    ->whereEquals("FirstName", "Robert")
    ->toList();
```

> **Note**
>
> Refer to [Query an index by documentQuery](https://docs.ravendb.net/7.2/indexes/querying/query-index.php.md#query-an-index-by-documentquery) for more examples.

## Syntax {#syntax}

The definition for `documentQuery` is listed in the [Syntax section](https://docs.ravendb.net/7.2/querying/overview.php.md#syntax) of the [Query Overview](https://docs.ravendb.net/7.2/querying/overview.php.md).

## See also

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