Filter by Field Presence



Filter by field name

// 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();
// 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();
// Only documents that contain field 'FirstName' will be returned

from Employees
where exists("FirstName")

Filter by field path

// 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();
// 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();
// Only documents that contain the 'Latitude' property in the specified path will be returned

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

Syntax

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