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

# Filter by Field Presence

> Client language: Python. 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), [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 search for documents that contain a specific field by the field **name** or **path**,
>   use the [document\_query](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.python.md)
>   `where_exists` method.  
>   Documents that do not contain the specified field will be excluded from the query results.
>
> - In this page:
>   - [Filter by Field Name or Path](#filter-by-field-name-or-path)
>   - [Syntax](#syntax)
>   - [Examples](#examples)

## Filter by Field Name or Path

To search for documents that contain a specific field by the field's **name** or **path**,
pass the name or the path to `where_exists` as demonstrated below.

### Syntax

```python
def where_exists(self, field_name: str) -> DocumentQuery[_T]: ...
```

| Parameters | Type | Description |
| - | - | - |
| **field\_name** | `str` | Field Name or Path to filter documents by |

### Examples

Pass `where_exists` a string containing the field name or path.

- **Pass a Field Name**:

#### Query

```python
# Only documents that contain field 'first_name' will be returned
results = list(session.advanced.document_query(object_type=Employee).where_exists("first_name"))
```

#### RQL

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

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

- **Pass a Field Path**:

#### Query

```python
results = list(
  session.advanced.document_query(object_type=Employee).where_exists("address.location.latitude")
)
```

#### RQL

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

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.python.md)
- [Querying: Filtering](https://docs.ravendb.net/6.2/indexes/querying/filtering.python.md)
- [Query vs DocumentQuery](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/query-vs-document-query.python.md)
