Filter by Field Presence


  • Use method whereExists() to query for documents that contain a particular field.

  • A document that doesn't contain the specified field will be excluded from the query results.

  • In this page:


Filter by field name

// Only documents that contain field 'firstName' will be returned

await session.query({ collection: "Employees" })
    .whereExists("firstName");
    .all();
// 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

await session.query({ collection: "Employees" })
    .whereExists("address.location.latitude");
    .all();
// Only documents that contain the 'latitude' property in the specified path will be returned

from Employees
where exists("address.location.latitude")

Syntax

whereExists(fieldName);
Parameters Type Description
fieldName string The name / path of the document field to filter by