Skip to main content

Class: NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:38

LINQ-inspired typed collection for NoSQL / MongoDB document querying and persistence.

Mirrors the fluent API and operational patterns of DbSet<T>, providing LINQ queries, projections, pagination, aggregations, and CRUD mutations.

Type Parameters​

Type ParameterDefault type
T extends objectany

Constructors​

Constructor​

new NoSqlSet<T>(adapter, collectionName, query?): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:39

Parameters​

ParameterType
adapterINoSqlAdapter
collectionNamestring
queryDocumentQuery<T>

Returns​

NoSqlSet<T>

Methods​

where()​

Call Signature​

where(fn): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:64

Filters documents using a LINQ lambda, WhereClause builder callback, or property criteria.

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

NoSqlSet<T>

Example​
await users.where(u => u.age >= 18 && u.status === 'active').toList();
await users.where({ role: 'admin' }).toList();
await users.where(w => w.gt('score', 90).eq('verified', true)).toList();

Call Signature​

where(predicate): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:65

Filters documents using a LINQ lambda, WhereClause builder callback, or property criteria.

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

NoSqlSet<T>

Example​
await users.where(u => u.age >= 18 && u.status === 'active').toList();
await users.where({ role: 'admin' }).toList();
await users.where(w => w.gt('score', 90).eq('verified', true)).toList();

Call Signature​

where(predicate): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:66

Filters documents using a LINQ lambda, WhereClause builder callback, or property criteria.

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

NoSqlSet<T>

Example​
await users.where(u => u.age >= 18 && u.status === 'active').toList();
await users.where({ role: 'admin' }).toList();
await users.where(w => w.gt('score', 90).eq('verified', true)).toList();

whereIn()​

whereIn<K>(field, values): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:76

Filters documents with an IN array comparison.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)
valuesunknown[]

Returns​

NoSqlSet<T>


whereNotIn()​

whereNotIn<K>(field, values): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:88

Filters documents with a NOT IN comparison.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)
valuesunknown[]

Returns​

NoSqlSet<T>


whereBetween()​

whereBetween<K>(field, low, high): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:100

Filters documents with a BETWEEN range comparison.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)
lowunknown
highunknown

Returns​

NoSqlSet<T>


whereRegex()​

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

Defined in: src/nosql/NoSqlSet.ts:113

Filters documents with a regular expression pattern.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
fieldK | ((entity) => unknown)undefined
patternstring | RegExpundefined
optionsstring'i'

Returns​

NoSqlSet<T>


whereNull()​

whereNull<K>(field): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:126

Filters documents where a field is null or undefined.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)

Returns​

NoSqlSet<T>


whereNotNull()​

whereNotNull<K>(field): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:135

Filters documents where a field is not null.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)

Returns​

NoSqlSet<T>


select()​

select<K>(...fields): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:151

Projects only specific fields from the documents.

Type Parameters​

Type Parameter
K extends string

Parameters​

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

Returns​

NoSqlSet<T>

Example​

const summaries = await users.select('id', 'name', 'email').toList();

orderBy()​

orderBy<K>(field, direction?): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:162

Sorts the documents in ascending order by the given field or selector.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
fieldK | ((entity) => unknown)undefined
direction"desc" | "asc"'asc'

Returns​

NoSqlSet<T>


orderByDescending()​

orderByDescending<K>(field): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:174

Sorts the documents in descending order by the given field or selector.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)

Returns​

NoSqlSet<T>


thenBy()​

thenBy<K>(field, direction?): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:183

Chained secondary sort.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterTypeDefault value
fieldK | ((entity) => unknown)undefined
direction"desc" | "asc"'asc'

Returns​

NoSqlSet<T>


thenByDescending()​

thenByDescending<K>(field): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:193

Chained secondary descending sort.

Type Parameters​

Type Parameter
K extends string

Parameters​

ParameterType
fieldK | ((entity) => unknown)

Returns​

NoSqlSet<T>


skip()​

skip(count): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:202

Skips the specified number of documents (LINQ Skip).

Parameters​

ParameterType
countnumber

Returns​

NoSqlSet<T>


take()​

take(count): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:211

Takes the specified maximum number of documents (LINQ Take / Limit).

Parameters​

ParameterType
countnumber

Returns​

NoSqlSet<T>


limit()​

limit(count): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:217

Parameters​

ParameterType
countnumber

Returns​

NoSqlSet<T>


offset()​

offset(count): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:221

Parameters​

ParameterType
countnumber

Returns​

NoSqlSet<T>


toList()​

toList(): Promise<T[]>

Defined in: src/nosql/NoSqlSet.ts:230

Executes the query and returns the matching documents as an array (LINQ ToList / ToArray).

Returns​

Promise<T[]>


toArray()​

toArray(): Promise<T[]>

Defined in: src/nosql/NoSqlSet.ts:247

Alias for toList().

Returns​

Promise<T[]>


first()​

Call Signature​

first(predicate?): Promise<T | null>

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

Returns the first document matching the query, or null if empty.

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

Promise<T | null>

Call Signature​

first(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:255

Returns the first document matching the query, or null if empty.

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T | null>


find()​

find(id): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:271

Finds a document by its primary key / ID (_id or id).

Parameters​

ParameterType
idunknown

Returns​

Promise<T | null>


findById()​

findById(id): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:279

Alias for find(id).

Parameters​

ParameterType
idunknown

Returns​

Promise<T | null>


firstOrDefault()​

Call Signature​

firstOrDefault(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:286

Returns the first document or null (alias for first()).

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

Promise<T | null>

Call Signature​

firstOrDefault(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:287

Returns the first document or null (alias for first()).

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T | null>


firstOrThrow()​

Call Signature​

firstOrThrow(predicate?): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:295

Returns the first document, or throws EntityNotFoundException if none matches.

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

Promise<T>

Call Signature​

firstOrThrow(predicate?): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:296

Returns the first document, or throws EntityNotFoundException if none matches.

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T>


single()​

Call Signature​

single(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:310

Asserts that at most one document matches the query and returns it, or returns null.

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

Promise<T | null>

Call Signature​

single(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:311

Asserts that at most one document matches the query and returns it, or returns null.

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T | null>


singleOrDefault()​

Call Signature​

singleOrDefault(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:323

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

Promise<T | null>

Call Signature​

singleOrDefault(predicate?): Promise<T | null>

Defined in: src/nosql/NoSqlSet.ts:324

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T | null>


singleOrThrow()​

Call Signature​

singleOrThrow(predicate?): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:329

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

Promise<T>

Call Signature​

singleOrThrow(predicate?): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:330

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<T>


count()​

Call Signature​

count(predicate?): Promise<number>

Defined in: src/nosql/NoSqlSet.ts:350

Returns the total count of documents matching the query (LINQ Count).

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

Promise<number>

Call Signature​

count(predicate?): Promise<number>

Defined in: src/nosql/NoSqlSet.ts:351

Returns the total count of documents matching the query (LINQ Count).

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<number>


any()​

Call Signature​

any(predicate?): Promise<boolean>

Defined in: src/nosql/NoSqlSet.ts:361

Checks whether any document matches the query (LINQ Any).

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

Promise<boolean>

Call Signature​

any(predicate?): Promise<boolean>

Defined in: src/nosql/NoSqlSet.ts:362

Checks whether any document matches the query (LINQ Any).

Parameters​
ParameterType
predicate?Record<string, unknown> | Partial<T>
Returns​

Promise<boolean>


all()​

all(predicate): Promise<boolean>

Defined in: src/nosql/NoSqlSet.ts:372

Checks whether all documents in the collection match the predicate (LINQ All).

Parameters​

ParameterType
predicate(entity) => boolean

Returns​

Promise<boolean>


sum()​

sum(field): Promise<number>

Defined in: src/nosql/NoSqlSet.ts:382

Calculates the sum of a numeric field using an aggregation pipeline.

Parameters​

ParameterType
fieldNoSqlFieldSelector<T>

Returns​

Promise<number>


avg()​

avg(field): Promise<number>

Defined in: src/nosql/NoSqlSet.ts:404

Calculates the average of a numeric field using an aggregation pipeline.

Parameters​

ParameterType
fieldNoSqlFieldSelector<T>

Returns​

Promise<number>


min()​

min(field): Promise<any>

Defined in: src/nosql/NoSqlSet.ts:426

Finds the minimum value of a field.

Parameters​

ParameterType
fieldNoSqlFieldSelector<T>

Returns​

Promise<any>


max()​

max(field): Promise<any>

Defined in: src/nosql/NoSqlSet.ts:448

Finds the maximum value of a field.

Parameters​

ParameterType
fieldNoSqlFieldSelector<T>

Returns​

Promise<any>


paginate()​

paginate(page?, pageSize?): Promise<NoSqlPagedResult<T>>

Defined in: src/nosql/NoSqlSet.ts:470

Performs offset-based pagination and returns a paged result container.

Parameters​

ParameterTypeDefault value
pagenumber1
pageSizenumber20

Returns​

Promise<NoSqlPagedResult<T>>


stream()​

stream(): AsyncIterable<T>

Defined in: src/nosql/NoSqlSet.ts:493

Streams documents asynchronously using the adapter cursor.

Returns​

AsyncIterable<T>


add()​

add(doc): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:514

Adds a single document to the collection.

Parameters​

ParameterType
docT

Returns​

Promise<T>


insert()​

insert(doc): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:526

Alias for add(doc).

Parameters​

ParameterType
docT

Returns​

Promise<T>


addMany()​

addMany(docs): Promise<T[]>

Defined in: src/nosql/NoSqlSet.ts:533

Adds multiple documents to the collection.

Parameters​

ParameterType
docsT[]

Returns​

Promise<T[]>


insertMany()​

insertMany(docs): Promise<T[]>

Defined in: src/nosql/NoSqlSet.ts:541

Alias for addMany(docs).

Parameters​

ParameterType
docsT[]

Returns​

Promise<T[]>


update()​

update(filter, changes): Promise<UpdateResult>

Defined in: src/nosql/NoSqlSet.ts:548

Updates matching documents with the specified changes.

Parameters​

ParameterType
filterNoSqlFilter | Partial<T>
changesNoSqlUpdate | Partial<T>

Returns​

Promise<UpdateResult>


remove()​

remove(filter): Promise<DeleteResult>

Defined in: src/nosql/NoSqlSet.ts:562

Removes matching documents from the collection.

Parameters​

ParameterType
filterNoSqlFilter | Partial<T>

Returns​

Promise<DeleteResult>


upsert()​

upsert(filter, doc): Promise<T>

Defined in: src/nosql/NoSqlSet.ts:569

Upserts a document based on unique filter criteria.

Parameters​

ParameterType
filterNoSqlFilter | Partial<T>
docT

Returns​

Promise<T>


lookup()​

lookup(options): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:579

Adds a $lookup aggregation stage to join with another collection.

Parameters​

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

Returns​

NoSqlSet<T>


unwind()​

unwind(path): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:593

Adds an $unwind aggregation stage to deconstruct an array field.

Parameters​

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

Returns​

NoSqlSet<T>


group()​

group(id, accumulators?): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:604

Adds a $group aggregation stage to group documents by id with accumulators.

Parameters​

ParameterType
idany
accumulators?Record<string, any>

Returns​

NoSqlSet<T>


facet()​

facet(facets): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:613

Adds a $facet aggregation stage to process multiple pipelines.

Parameters​

ParameterType
facetsRecord<string, AggregationStage[]>

Returns​

NoSqlSet<T>


addFields()​

addFields(fields): NoSqlSet<T>

Defined in: src/nosql/NoSqlSet.ts:622

Adds an $addFields aggregation stage.

Parameters​

ParameterType
fieldsRecord<string, any>

Returns​

NoSqlSet<T>


createIndex()​

createIndex(keys, options?): Promise<string>

Defined in: src/nosql/NoSqlSet.ts:631

Creates an index on this collection.

Parameters​

ParameterType
keysRecord<string, 1 | -1 | "text" | "2dsphere" | string>
options?{ unique?: boolean; name?: string; background?: boolean; ttl?: number; }
options.unique?boolean
options.name?string
options.background?boolean
options.ttl?number

Returns​

Promise<string>


aggregate()​

aggregate<R>(pipeline?): Promise<R[]>

Defined in: src/nosql/NoSqlSet.ts:646

Runs the compiled aggregation pipeline (or custom pipeline) on this collection.

Type Parameters​

Type ParameterDefault type
Rany

Parameters​

ParameterType
pipeline?AggregationStage[]

Returns​

Promise<R[]>


getRawCollection()​

getRawCollection<R>(): R

Defined in: src/nosql/NoSqlSet.ts:654

Returns the underlying driver collection instance.

Type Parameters​

Type ParameterDefault type
Rany

Returns​

R


getCompiledFilter()​

getCompiledFilter(): NoSqlFilter

Defined in: src/nosql/NoSqlSet.ts:664

Returns the compiled MongoDB filter object for this query.

Returns​

NoSqlFilter


getCompiledFindOptions()​

getCompiledFindOptions(): FindOptions

Defined in: src/nosql/NoSqlSet.ts:671

Returns the compiled FindOptions for this query.

Returns​

FindOptions

Properties​

collectionName​

readonly collectionName: string

Defined in: src/nosql/NoSqlSet.ts:41