Filter by Field Presence
-
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
/** @var array<Employee> $results */
$results = $session
->advanced()
->documentQuery(Employee::class)
->whereExists("FirstName")
->toList();
// Only documents that contain field 'FirstName' will be returned
from Employees
where exists("FirstName")
Filter by field path
$results = $session
->advanced()
->documentQuery(Employee::class)
->whereExists("Address.Location.Latitude")
->toList();
// Only documents that contain the 'Latitude' property in the specified path will be returned
from Employees
where exists("Address.Location.Latitude")
Syntax
public function whereExists(?string $fieldName): DocumentQueryInterface;
Parameters | Type | Description |
---|---|---|
$fieldName | ?string |
The name / path of the document field to filter by |