Session: Querying: What is a Document Query?

Querying capabilities can be accessed via the documentQuery() method in advanced session operations. DocumentQuery gives you more flexibility and control over the process of building a query.

Syntax

session.advanced.documentQuery(documentType);

session.advanced.documentQuery({
    indexName,
    collectionName,
    isMapReduce,
    documentType
});
Parameters
documentType class A class constructor used for reviving the results' entities from which the collection name is determined
options object
  indexName string Name of an index to perform a query on (exclusive with collectionName)
  collection string Name of a collection to perform a query on (exclusive with indexName)
  isMapReduce bool Indicates if a queried index is a map/reduce index (modifies how we treat identifier properties)
  documentType function A class constructor used for reviving the results' entities
Return Value
Promise<IDocumentQuery> Promise resolving to query instance implementing IDocumentQuery interface containing additional query methods and extensions

Example I - Basic

// load all entities from 'Employees' collection
const employees = await session.advanced
    .documentQuery(Employee)
    .all();

// same as
const employees2 = await session.advanced
    .documentQuery({ collection: "Employees" })
    .all();

// load all entities from 'Employees' collection
// where firstName equals 'Robert'
const employees = await session.advanced
    .documentQuery({ collection: "Employees" })
    .whereEquals("FirstName", "Robert")
    .all();

Example II - Querying Specified Index

// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'My/Custom/Index'
const employees = await session.advanced
    .documentQuery({ indexName: "My/Custom/Index" })
    .whereEquals("FirstName", "Robert")
    .all();

Custom Methods and Extensions

Note

Functionality of most of the methods match the functionality of their query counterparts and therefore will not be described again. Please refer to the appropriate counterpart documentation articles. Links starting with [query] are marking those articles.

Document query object is an event emitter emitting the following events:

  • 'afterQueryExecuted`
  • 'beforeQueryExecuted`

Available methods:

Remarks

By default, if the page size is not specified, all of the matching records will be retrieved from a database.