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
<T> IDocumentQuery<T> documentQuery(Class<T> clazz);
<T> IDocumentQuery<T> documentQuery(Class<T> clazz, String indexName, String collectionName, boolean isMapReduce);
Parameters | ||
---|---|---|
indexName | String | Name of an index to perform a query on (mutually exclusive with collectionName) |
collectionName | String | Name of a collection to perform a query on (mutually exclusive with indexName) |
isMapReduce | bool | Indicates if a queried index is a map-reduce index (modifies how we treat identifier properties) |
Return Value | |
---|---|
IDocumentQuery | Instance implementing IDocumentQuery interface containing additional query methods and extensions |
Example I - Basic
// load all entities from 'Employees' collection
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class)
.toList();
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class)
.whereEquals("FirstName", "Robert")
.toList();
Example II - Querying Specified Index
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'My/Custom/Index'
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class, "My/Custom/Index", null, false)
.whereEquals("FirstName", "Robert")
.toList();
or
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
// using 'My/Custom/Index'
List<Employee> employees = session
.advanced()
.documentQuery(Employee.class, MyCustomIndex.class)
.whereEquals("FirstName", "Robert")
.toList();
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.
Available methods:
- addAfterQueryExecutedListener
- addBeforeQueryExecutedListener
- addOrder
- addParameter
- [Query] aggregateBy
- [Query] aggregateUsing
- andAlso
- boost
- closeSubclause
- containsAll
- containsAny
- count
- countLazily
- distinct
- first
- firstOrDefault
- fuzzy
- groupBy
- groupByArrayValues
- groupByArrayContent
- include
- intersect
- invokeAfterQueryExecuted
- invokeAfterStreamExecuted
- [Query] lazily
- moreLikeThis
- negateNext
- [Query] noCaching
- not
- [Query] noTracking
- ofType
- openSubclause
- orderBy
- orderByDescending
- [Query] orderByDistance
- [Query] orderByDistanceDescending
- orderByScore
- orderByScoreDescending
- orElse
- proximity
- randomOrdering
- [Query] relatesToShape
- search
- selectFields
- single
- singleOrDefault
- skip
- [Query] spatial
- statistics
- suggestUsing
- take
- usingDefaultOperator
- [Query] waitForNonStaleResults
- [Query] waitForNonStaleResultsAsOf
- where
- whereBetween
- whereEndsWith
- whereEquals
- whereExists
- whereGreaterThan
- whereGreaterThanOrEqual
- whereIn
- whereLessThan
- whereLessThanOrEqual
- whereLucene
- whereNotEquals
- whereRegex
- whereStartsWith
- withinRadiusOf
Remarks
By default, if the page size
is not specified, all of the matching records will be retrieved from a database.