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.
Go to Latest
method mongoose.Schema.prototype.pre
import { mongoose } from "https://deno.land/x/mongoose@8.7.0/types/index.d.ts";
const { Schema } = mongoose;

Defines a pre hook for the model.

Type Parameters

optional
T = never

Parameters

method: "save"
options: SchemaPreOptions & { document: false; query: boolean; }
fn: PreSaveMiddlewareFunction<T>

Type Parameters

optional
T = never

Parameters

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

Type Parameters

optional
T = never

Parameters

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

Type Parameters

optional
T = never

Parameters

method: MongooseDistinctDocumentMiddleware | MongooseDistinctDocumentMiddleware[] | RegExp
options: SchemaPreOptions & { document: false; query: boolean; }
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = THydratedDocumentType | Query<any, any>

Parameters

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

Type Parameters

optional
T = THydratedDocumentType

Parameters

method: "save"
fn: PreSaveMiddlewareFunction<T>

Type Parameters

optional
T = THydratedDocumentType

Parameters

method: MongooseDistinctDocumentMiddleware | MongooseDistinctDocumentMiddleware[]
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = THydratedDocumentType

Parameters

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

Type Parameters

optional
T = THydratedDocumentType

Parameters

method: MongooseQueryAndDocumentMiddleware | MongooseQueryAndDocumentMiddleware[] | RegExp
options: SchemaPreOptions & { document: true; }
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = THydratedDocumentType

Parameters

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

Type Parameters

optional
T = Query<any, any>

Parameters

method: MongooseDefaultQueryMiddleware | MongooseDefaultQueryMiddleware[]
fn: PreMiddlewareFunction<T>

Type Parameters

optional
T = Query<any, any>

Parameters

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

Type Parameters

optional
T = Query<any, any>

Parameters

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

Type Parameters

optional
T = THydratedDocumentType | Query<any, any>

Parameters

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

Type Parameters

optional
T = THydratedDocumentType | Query<any, any>

Parameters

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

Type Parameters

T extends Aggregate<any>

Parameters

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

Type Parameters

optional
T = TModelType

Parameters

method: "insertMany" | RegExp
fn: (
this: T,
next: (err?: CallbackError) => void,
docs: any | Array<any>,
options?: InsertManyOptions & { lean?: boolean; },
) => void | Promise<void>

Type Parameters

optional
T = TModelType

Parameters

method: "bulkWrite" | RegExp
fn: (
this: T,
next: (err?: CallbackError) => void,
ops: Array<AnyBulkWriteOperation<any>>,
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions,
) => void | Promise<void>

Type Parameters

optional
T = TModelType

Parameters

method: "createCollection" | RegExp
fn: (
this: T,
next: (err?: CallbackError) => void,
options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, "expires">,
) => void | Promise<void>