Skip to main content

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();

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();

Syntax

IDocumentQuery<T> WhereExists(string fieldName);

IDocumentQuery<T> WhereExists<TValue>(Expression<Func<T, TValue>> propertySelector);
ParametersTypeDescription
fieldNamestringThe name / path of the document field to filter by
propertySelectorExpression<Func<T,TValue>>Lambda expression with name / path of the document field to filter by