---
title: "Filter by Field Presence"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field"
version: "6.2"
language: "php"
---

# Filter by Field Presence

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.md), [Java](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.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**
>
> - To query for documents that contain a particular field, use the `whereExists` extension method.
>
> - A document that doesn't contain the specified field will be excluded from the query results.
>
> - In this page:
>   - [Filter by field name](#filter-by-field-name)
>   - [Filter by field path](#filter-by-field-path)
>   - [Syntax](#syntax)

## Filter by field name

### whereExists

```php
/** @var array<Employee> $results */
$results = $session
  ->advanced()
  ->documentQuery(Employee::class)
  ->whereExists("FirstName")
  ->toList();
```

### RQL

```sql
// Only documents that contain field 'FirstName' will be returned

from Employees
where exists("FirstName")
```

## Filter by field path

### whereExists

```php
$results = $session
  ->advanced()
  ->documentQuery(Employee::class)
  ->whereExists("Address.Location.Latitude")
  ->toList();
```

### RQL

```sql
// Only documents that contain the 'Latitude' property in the specified path will be returned

from Employees
where exists("Address.Location.Latitude")
```

## Syntax

```php
public function whereExists(?string $fieldName): DocumentQueryInterface;
```

| Parameters | Type | Description |
| - | - | - |
| **$fieldName** | `?string` | The name / path of the document field to filter by |

## See also

- [What is a Document Query](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.php.md)
- [Querying: Filtering](https://docs.ravendb.net/6.2/indexes/querying/filtering.php.md)
- [Query vs DocumentQuery](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/query-vs-document-query.php.md)
