Skip to main content

Class: DocumentQuery<T>

Defined in: src/nosql/DocumentQuery.ts:13

LINQ query compiler for document-oriented databases (MongoDB).

Compiles TypeScript lambda predicates, WhereClause AST nodes, ordering expressions, projections, and pagination settings into native MongoDB query filter objects, sort specifications, and aggregation pipeline stages.

Type Parameters​

Type ParameterDefault type
Tany

Constructors​

Constructor​

new DocumentQuery<T>(collectionName): DocumentQuery<T>

Defined in: src/nosql/DocumentQuery.ts:23

Parameters​

ParameterType
collectionNamestring

Returns​

DocumentQuery<T>

Methods​

clone()​

clone(): DocumentQuery<T>

Defined in: src/nosql/DocumentQuery.ts:28

Clones this DocumentQuery instance immutably.

Returns​

DocumentQuery<T>


where()​

Call Signature​

where(fn): this

Defined in: src/nosql/DocumentQuery.ts:48

Adds a filter condition using a LINQ lambda, WhereClause builder callback, or partial filter object.

Parameters​
ParameterType
fn(clause) => boolean | void | WhereClause<T>
Returns​

this

Call Signature​

where(predicate): this

Defined in: src/nosql/DocumentQuery.ts:49

Adds a filter condition using a LINQ lambda, WhereClause builder callback, or partial filter object.

Parameters​
ParameterType
predicate(entity) => boolean
Returns​

this

Call Signature​

where(predicate): this

Defined in: src/nosql/DocumentQuery.ts:50

Adds a filter condition using a LINQ lambda, WhereClause builder callback, or partial filter object.

Parameters​
ParameterType
predicateRecord<string, unknown> | Partial<T>
Returns​

this


whereField()​

whereField<K>(field, op, value): this

Defined in: src/nosql/DocumentQuery.ts:82

Adds a direct comparison filter on a field.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K
opstring
valueunknown

Returns​

this


whereIn()​

whereIn<K>(field, values): this

Defined in: src/nosql/DocumentQuery.ts:95

Adds an $in condition on a field.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K
valuesunknown[]

Returns​

this


whereNotIn()​

whereNotIn<K>(field, values): this

Defined in: src/nosql/DocumentQuery.ts:107

Adds a $nin condition on a field.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K
valuesunknown[]

Returns​

this


whereBetween()​

whereBetween<K>(field, low, high): this

Defined in: src/nosql/DocumentQuery.ts:119

Adds a BETWEEN condition on a field.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K
lowunknown
highunknown

Returns​

this


whereRegex()​

whereRegex<K>(field, pattern, options?): this

Defined in: src/nosql/DocumentQuery.ts:132

Adds a regex pattern match condition on a string field.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
field((entity) => unknown) | Kundefined
patternstring | RegExpundefined
optionsstring'i'

Returns​

this


whereNull()​

whereNull<K>(field): this

Defined in: src/nosql/DocumentQuery.ts:149

Adds an IS NULL / null equality filter.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K

Returns​

this


whereNotNull()​

whereNotNull<K>(field): this

Defined in: src/nosql/DocumentQuery.ts:158

Adds an IS NOT NULL filter.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K

Returns​

this


orderBy()​

orderBy<K>(field, direction?): this

Defined in: src/nosql/DocumentQuery.ts:169

Adds an ascending ORDER BY sort specification.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
field((entity) => unknown) | Kundefined
direction"desc" | "asc"'asc'

Returns​

this


orderByDescending()​

orderByDescending<K>(field): this

Defined in: src/nosql/DocumentQuery.ts:181

Adds a descending ORDER BY sort specification.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K

Returns​

this


thenBy()​

thenBy<K>(field, direction?): this

Defined in: src/nosql/DocumentQuery.ts:188

Chained secondary sort (thenBy).

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
field((entity) => unknown) | Kundefined
direction"desc" | "asc"'asc'

Returns​

this


thenByDescending()​

thenByDescending<K>(field): this

Defined in: src/nosql/DocumentQuery.ts:198

Chained secondary descending sort (thenByDescending).

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
field((entity) => unknown) | K

Returns​

this


select()​

select<K>(...fields): this

Defined in: src/nosql/DocumentQuery.ts:207

Specifies which document fields to project (include).

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
...fields(((entity) => unknown) | K)[]

Returns​

this


skip()​

skip(count): this

Defined in: src/nosql/DocumentQuery.ts:220

Sets the number of documents to skip (Skip in LINQ).

Parameters​

ParameterType
countnumber

Returns​

this


take()​

take(count): this

Defined in: src/nosql/DocumentQuery.ts:228

Sets the maximum number of documents to take (Take in LINQ).

Parameters​

ParameterType
countnumber

Returns​

this


limit()​

limit(count): this

Defined in: src/nosql/DocumentQuery.ts:233

Parameters​

ParameterType
countnumber

Returns​

this


getSkip()​

getSkip(): number | undefined

Defined in: src/nosql/DocumentQuery.ts:237

Returns​

number | undefined


getLimit()​

getLimit(): number | undefined

Defined in: src/nosql/DocumentQuery.ts:241

Returns​

number | undefined


getInMemoryFilters()​

getInMemoryFilters(): (entity) => boolean[]

Defined in: src/nosql/DocumentQuery.ts:245

Returns​

(entity) => boolean[]


compileFilter()​

compileFilter(): NoSqlFilter

Defined in: src/nosql/DocumentQuery.ts:254

Compiles all attached WHERE conditions and filters into a single native MongoDB filter object.

Returns​

NoSqlFilter


compileSort()​

compileSort(): Record<string, -1 | 1> | undefined

Defined in: src/nosql/DocumentQuery.ts:314

Compiles the sort criteria into a MongoDB sort object (e.g. { createdAt: -1, name: 1 }).

Returns​

Record<string, -1 | 1> | undefined


compileProjection()​

compileProjection(): Record<string, 0 | 1> | undefined

Defined in: src/nosql/DocumentQuery.ts:326

Compiles the projection fields into a MongoDB projection object (e.g. { name: 1, email: 1 }).

Returns​

Record<string, 0 | 1> | undefined


compileFindOptions()​

compileFindOptions(): FindOptions

Defined in: src/nosql/DocumentQuery.ts:333

Compiles complete FindOptions for INoSqlAdapter.find().

Returns​

FindOptions


stage()​

stage(stage): this

Defined in: src/nosql/DocumentQuery.ts:347

Appends an arbitrary aggregation stage to the pipeline.

Parameters​

ParameterType
stageAggregationStage

Returns​

this


lookup()​

lookup(options): this

Defined in: src/nosql/DocumentQuery.ts:355

Performs a $lookup join with another collection.

Parameters​

ParameterType
options{ from: string; localField: string; foreignField: string; as: string; }
options.fromstring
options.localFieldstring
options.foreignFieldstring
options.asstring

Returns​

this


unwind()​

unwind(path): this

Defined in: src/nosql/DocumentQuery.ts:367

Deconstructs an array field from the input documents to output a document for each element ($unwind).

Parameters​

ParameterType
pathstring | { path: string; preserveNullAndEmptyArrays?: boolean; }

Returns​

this


group()​

group(id, accumulators?): this

Defined in: src/nosql/DocumentQuery.ts:379

Groups input documents by a specified identifier expression and applies accumulator expressions ($group).

Parameters​

ParameterType
idany
accumulatorsRecord<string, any>

Returns​

this


facet()​

facet(facets): this

Defined in: src/nosql/DocumentQuery.ts:386

Processes multiple aggregation pipelines within a single stage on the same set of input documents ($facet).

Parameters​

ParameterType
facetsRecord<string, AggregationStage[]>

Returns​

this


addFields()​

addFields(fields): this

Defined in: src/nosql/DocumentQuery.ts:393

Adds new fields to documents ($addFields).

Parameters​

ParameterType
fieldsRecord<string, any>

Returns​

this


project()​

project(spec): this

Defined in: src/nosql/DocumentQuery.ts:400

Passes along the documents with the requested fields to the next stage in the pipeline ($project).

Parameters​

ParameterType
specRecord<string, any>

Returns​

this


compileAggregationPipeline()​

compileAggregationPipeline(extraStages?): AggregationStage[]

Defined in: src/nosql/DocumentQuery.ts:407

Compiles the current query into an Aggregation Pipeline.

Parameters​

ParameterTypeDefault value
extraStagesAggregationStage[][]

Returns​

AggregationStage[]

Properties​

collectionName​

readonly collectionName: string

Defined in: src/nosql/DocumentQuery.ts:23