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

# Filter by Field Presence

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-filter-by-field.php.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 filter documents by whether they contain a particular field, use the LINQ extension method `whereExists()` accessible
>   from the [Document Query](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.java.md).
>
> - If a document doesn't contain the specified field, it is excluded from the query results.
>
> - In this page:
>   - [Syntax](#syntax)
>   - [Examples](#examples)

## Syntax

```java
IDocumentQuery<T> whereExists(String fieldName);
```

| Parameters | Type | Description |
| - | - | - |
| **fieldName** | `String` | The name or path to the field you want to filter by |

## Examples

#### Filter by Field Name

##### Java

```java
List<Employee> results = session
      .advanced()
      .documentQuery(Employee.class)
      .whereExists("FirstName")
      .toList();
```

##### RQL

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

#### Filter by the Path to a Field

##### Java

```java
List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("Address.Location.Latitude")
.toList();
```

##### RQL

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

## See also

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