Filter by Field Presence

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.


def where_exists(self, field_name: str) -> DocumentQuery[_T]: ...
Parameters Type Description
field_name str Field Name or Path to filter documents by


Pass where_exists a string containing the field name or path.

  • Pass a Field Name:

    # Only documents that contain field 'first_name' will be returned
    results = list(session.advanced.document_query(object_type=Employee).where_exists("first_name"))
    // Only documents that contain the 'FirstName' field will be returned
    from Employees
    where exists("FirstName")
  • Pass a Field Path:

    results = list(
    // Only documents that contain the 'Latitude' property in the specified path will be returned
    from Employees
    where exists("Address.Location.Latitude")