Skip to content

@iamcalegari/mongoat / HookContextMap

Interface: HookContextMap<ModelType> ​

Defined in: src/types/hooks.ts:88

ctx shape per METHODS value — a lookup type keyed by the method literal so pre<M extends METHODS>(method: M, fn: (ctx: HookContextMap<ModelType>[M]) => ...) infers the right ctx from M.

ctx.options/ctx.filter/ctx.document(s) are the SAME reference used in the driver call — a pre-hook mutation reaches the driver.

INSERT_MANY deviates from a literal single-documents array: pre hooks run PER DOCUMENT (parallel across documents, sequential across hooks of the SAME document), so ctx.document is the document currently being processed while ctx.documents stays available as the full batch (e.g. for cross-document checks). Post hooks run ONCE for the whole batch — ctx.document is not meaningful there, only ctx.documents/ctx.result.

Type Parameters ​

ModelType ​

ModelType extends Document

Properties ​

aggregate ​

aggregate: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:142

Type Declaration ​

options ​

options: AggregateOptions

pipeline ​

pipeline: Document[]

result? ​

optional result?: Document[]


bulkWrite ​

bulkWrite: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:147

Type Declaration ​

operations ​

operations: AnyBulkWriteOperation<ModelType>[]

options ​

options: BulkWriteOptions

result? ​

optional result?: BulkWriteResult


delete ​

delete: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:127

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: FindOneAndDeleteOptions

result? ​

optional result?: WithId<ModelType> | null


deleteMany ​

deleteMany: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:132

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: DeleteOptions

result? ​

optional result?: DeleteResult


find ​

find: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:100

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: FindOptions

result? ​

optional result?: WithId<ModelType> | null


findById ​

findById: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:110

Type Declaration ​

documentId ​

documentId: string | ObjectId

options ​

options: FindOptions

result? ​

optional result?: WithId<ModelType> | null


findMany ​

findMany: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:105

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: FindOptions

result? ​

optional result?: WithId<ModelType>[]


insert ​

insert: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:89

Type Declaration ​

document ​

document: OptionalUnlessRequiredId<ModelType>

options ​

options: InsertOneOptions

result? ​

optional result?: EnhancedOmit<ModelType, "_id"> & object & DefaultProperties


insertMany ​

insertMany: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:94

Type Declaration ​

document? ​

optional document?: OptionalUnlessRequiredId<ModelType>

documents ​

documents: OptionalUnlessRequiredId<ModelType>[]

options ​

options: BulkWriteOptions

result? ​

optional result?: InsertManyResult<ModelType>


total ​

total: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:137

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: CountDocumentsOptions

result? ​

optional result?: number


update ​

update: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:115

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: FindOneAndUpdateOptions

result? ​

optional result?: WithId<ModelType> | null

update ​

update: UpdateFilter<ModelType>


updateMany ​

updateMany: BaseHookContext<ModelType> & object

Defined in: src/types/hooks.ts:121

Type Declaration ​

filter ​

filter: Filter<ModelType>

options ​

options: UpdateOptions

result? ​

optional result?: UpdateResult<Document>

update ​

update: UpdateFilter<ModelType>