Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/mongoose/types/index.d.ts>mongoose.Schema#pre

MongoDB object modeling designed to work in an asynchronous environment.
Latest
method mongoose.Schema.prototype.pre
import { mongoose } from "https://deno.land/x/mongoose@6.13.4/types/index.d.ts";
const { Schema } = mongoose;

Defines a pre hook for the model.

Type Parameters

optional
T = HydratedDocument<DocType, TInstanceMethods>

Parameters

method: DocumentOrQueryMiddleware | DocumentOrQueryMiddleware[]
options: SchemaPreOptions & { document: true; query: false; }
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = Query<any, any>

Parameters

method: DocumentOrQueryMiddleware | DocumentOrQueryMiddleware[]
options: SchemaPreOptions & { document: false; query: true; }
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = HydratedDocument<DocType, TInstanceMethods>

Parameters

method: "save"
fn: PreSaveMiddlewareFunction<T>

Type Parameters

optional
T = HydratedDocument<DocType, TInstanceMethods>

Parameters

method: "save"
options: SchemaPreOptions
fn: PreSaveMiddlewareFunction<T>

Type Parameters

optional
T = Query<any, any>

Parameters

method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = Query<any, any>

Parameters

method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp
options: SchemaPreOptions
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = HydratedDocument<DocType, TInstanceMethods>

Parameters

method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = HydratedDocument<DocType, TInstanceMethods>

Parameters

method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp
options: SchemaPreOptions
fn: PreMiddlewareFunction<T>

Type Parameters

T extends Aggregate<any>

Parameters

method: "aggregate" | RegExp
fn: PreMiddlewareFunction<T>

Type Parameters

T extends Aggregate<any>

Parameters

method: "aggregate" | RegExp
options: SchemaPreOptions
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = M

Parameters

method: "insertMany" | RegExp
fn: (
this: T,
next: (err?: CallbackError) => void,
docs: any | Array<any>,
) => void | Promise<void>

Type Parameters

optional
T = M

Parameters

method: "insertMany" | RegExp
options: SchemaPreOptions
fn: (
this: T,
next: (err?: CallbackError) => void,
docs: any | Array<any>,
) => void | Promise<void>