Session: Querying: How to Filter by Field Presence
-
To filter documents by whether they contain a particular field, use the LINQ extension method
whereExists()
accessible from the Document Query. -
If a document doesn't contain the specified field, it is excluded from the query results.
-
In this page:
Syntax
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
List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("FirstName")
.toList();
from Employees
where exists("FirstName")
Filter by the Path to a Field
List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("Address.Location.Latitude")
.toList();
from Employees
where exists("Address.Location.Latitude")