What is a Document Query?
-
RavenDB queries can be executed via
query
,documentQuery
or directly usingRQL
.
Learn more in Query Overview. -
See Query -vs- documentQuery for additional details.
-
In this page:
documentQuery examples
Query collection - no filtering
// load all entities from 'Employees' collection
$employees = $session
->advanced()
->documentQuery(Employee::class)
->toList();
from "Employees"
Query collection - with filtering
// load all entities from 'Employees' collection
// where firstName equals 'Robert'
$employees = $session
->advanced()
->documentQuery(Employee::class)
->whereEquals("FirstName", "Robert")
->toList();
from "Employees" where FirstName == "Robert"
Query an index
-
Using a Path string
)// load all entities from 'Employees' collection // where firstName equals 'Robert' // using 'My/Custom/Index' $employees = $session ->advanced() ->documentQuery(Employee::class, "My/Custom/Index", null, false) ->whereEquals("FirstName", "Robert") ->toList();
-
Using an index Class
)// load all entities from 'Employees' collection // where firstName equals 'Robert' // using 'MyCustomIndex::class' $employees = $session ->advanced() ->documentQuery(Employee::class, MyCustomIndex::class) ->whereEquals("FirstName", "Robert") ->toList();
Please refer to Querying an index for examples of querying an index using a documentQuery.
Custom Methods
Several methods share the same functionality as their query
counterparts.
Refer to the corresponding documentation articles, marked with links starting with "[Query]" in the list below.
Available custom methods:
- AddOrder
- [query] afterQueryExecuted
- [query] afterStreamExecuted
- [query] aggregateBy
- [query] aggregateUsing
- andAlso
- [query] beforeQueryExecuted
- boost
- closeSubclause
- cmpXchg
- containsAll
- containsAny
- count
- countLazily
- distinct
- explainScores
- first
- firstOrDefault
- fuzzy
- getIndexQuery
- getQueryResult
- groupBy
- groupByArrayValues
- groupByArrayContent
- [query] Highlight
- include
- includeExplanations
- intersect
- invokeAfterQueryExecuted
- invokeAfterStreamExecuted
- [query] lazily
- longCount
- moreLikeThis
- negateNext
- not
- [query] noCaching
- [query] noTracking
- ofType
- openSubclause
- orderBy
- orderByDescending
- [query] orderByDistance
- [query] orderByDistanceDescending
- orderByScore
- orderByScoreDescending
- orElse
- [query] projection
- proximity
- [query] randomOrdering
- [query] relatesToShape
- search
- selectFields
- selectTimeSeries
- single
- singleOrDefault
- skip
- [query] spatial
- statistics
- suggestUsing
- take
- [query] timings
- usingDefaultOperator
- [query] waitForNonStaleResults
- where
- whereBetween
- whereEndsWith
- whereEquals
- whereExists
- whereGreaterThan
- whereGreaterThanOrEqual
- whereIn
- whereLessThan
- whereLessThanOrEqual
- whereLucene
- whereNotEquals
- whereRegex
- whereStartsWith
- withinRadiusOf
Syntax
The definition for documentQuery
is listed in the Syntax section
of the Query Overview.