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

# Filter by Field Presence

> Client language: C#. Also available for [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), [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 query for documents that contain a particular field,  
>   use extension method `WhereExists()` which is accessible from [DocumentQuery](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/what-is-document-query.md).
>
> - 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

### Sync

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

List<Employee> results = session
  .Advanced
  .DocumentQuery<Employee>()
  .WhereExists("FirstName")
   // Or use lambda expression: .WhereExists(x => x.FirstName)
  .ToList();
```

### Async

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

List<Employee> results = await asyncSession
  .Advanced
  .AsyncDocumentQuery<Employee>()
  .WhereExists("FirstName")
   // Or use lambda expression: .WhereExists(x => x.FirstName)
  .ToListAsync();
```

### RQL

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

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

## Filter by field path

### Sync

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

List<Employee> results = session
  .Advanced
  .DocumentQuery<Employee>()
  .WhereExists("Address.Location.Latitude")
   // Or use lambda expression: .WhereExists(x => x.Address.Location.Latitude)
  .ToList();
```

### Async

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

List<Employee> results = await asyncSession
  .Advanced
  .AsyncDocumentQuery<Employee>()
  .WhereExists("Address.Location.Latitude")
   // Or use lambda expression: .WhereExists(x => x.Address.Location.Latitude)
  .ToListAsync();
```

### RQL

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

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

## Syntax

```csharp
IDocumentQuery<T> WhereExists(string fieldName);

IDocumentQuery<T> WhereExists<TValue>(Expression<Func<T, TValue>> propertySelector);
```

| Parameters | Type | Description |
| - | - | - |
| **fieldName** | `string` | The name / path of the document field to filter by |
| **propertySelector** | `Expression<Func<T,TValue>>` | Lambda expression with 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.md)
- [Querying: Filtering](https://docs.ravendb.net/6.2/indexes/querying/filtering.md)
- [Query vs DocumentQuery](https://docs.ravendb.net/6.2/client-api/session/querying/document-query/query-vs-document-query.md)
