@typegoose/typegoose

  • Version 12.4.0
  • Published
  • 282 kB
  • 5 dependencies
  • MIT license

Install

npm i @typegoose/typegoose
yarn add @typegoose/typegoose
pnpm add @typegoose/typegoose

Overview

Define Mongoose models using TypeScript classes

Index

Variables

Functions

Classes

Enums

Type Aliases

Namespaces

Variables

variable LogLevels

const LogLevels: logger.LogLevel;

    variable post

    const post: {
    <
    S extends unknown,
    T = S extends Query<any, any, {}, any, 'find'>
    ? S
    : Query<any, any, {}, any, 'find'>
    >(
    method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp,
    fn: ErrorHandlingMiddlewareFunction<T>,
    options: SchemaPostOptions & { errorHandler: true }
    ): ClassDecorator;
    <
    S_1 extends unknown,
    T_1 = S_1 extends Document<any, any, any> ? S_1 : HydratedDocument<any, any>
    >(
    method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp,
    fn: ErrorHandlingMiddlewareFunction<T_1>,
    options: SchemaPostOptions & { errorHandler: true }
    ): ClassDecorator;
    <T_2 extends Aggregate<any>>(
    method: 'aggregate' | RegExp,
    fn: ErrorHandlingMiddlewareFunction<T_2, any[]>,
    options: SchemaPostOptions & { errorHandler: true }
    ): ClassDecorator;
    <
    S_2 extends unknown,
    T_3 = S_2 extends Model<any, {}, {}, {}, any, any> ? S_2 : any
    >(
    method: 'insertMany' | RegExp,
    fn: ErrorHandlingMiddlewareFunction<T_3>,
    options: SchemaPostOptions & { errorHandler: true }
    ): ClassDecorator;
    <S_3 extends never, T_4 = S_3>(
    method:
    | MongooseQueryOrDocumentMiddleware
    | MongooseQueryOrDocumentMiddleware[]
    | RegExp,
    fn: PostMiddlewareFunction<T_4, T_4>,
    options?: SchemaPostOptions & { document: false; query: false }
    ): ClassDecorator;
    <S_4 extends never, T_5 = S_4>(
    method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
    fn: PostMiddlewareFunction<T_5, T_5>,
    options?: SchemaPostOptions & { document: boolean; query: false }
    ): ClassDecorator;
    <S_5 extends never, T_6 = S_5>(
    method:
    | MongooseDistinctDocumentMiddleware
    | MongooseDistinctDocumentMiddleware[],
    fn: PostMiddlewareFunction<T_6, T_6>,
    options?: SchemaPostOptions & { document: false; query: true }
    ): ClassDecorator;
    <
    S_6 extends unknown,
    T_7 = S_6 extends Document<any, any, any> ? S_6 : HydratedDocument<any, any>
    >(
    method:
    | MongooseDistinctDocumentMiddleware
    | MongooseDistinctDocumentMiddleware[],
    fn: PostMiddlewareFunction<T_7, T_7>,
    options?: SchemaPostOptions
    ): ClassDecorator;
    <
    S_7 extends unknown,
    T_8 = S_7 extends Document<any, any, any> ? S_7 : HydratedDocument<any, any>
    >(
    method:
    | MongooseQueryOrDocumentMiddleware
    | MongooseQueryOrDocumentMiddleware[]
    | RegExp,
    fn: PostMiddlewareFunction<T_8, T_8>,
    options?: SchemaPostOptions & { document: true; query: false }
    ): ClassDecorator;
    <
    S_8 extends unknown,
    T_9 = S_8 extends Query<any, any, {}, any, 'find'>
    ? S_8
    : Query<any, any, {}, any, 'find'>
    >(
    method: MongooseDefaultQueryMiddleware | MongooseDefaultQueryMiddleware[],
    fn: PostMiddlewareFunction<T_9, QueryResultType<T_9>>
    ): ClassDecorator;
    <
    S_9 extends unknown,
    T_10 = S_9 extends Query<any, any, {}, any, 'find'>
    ? S_9
    : Query<any, any, {}, any, 'find'>
    >(
    method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
    fn: PostMiddlewareFunction<T_10, QueryResultType<T_10>>,
    options?: SchemaPostOptions
    ): ClassDecorator;
    <
    S_10 extends unknown,
    T_11 = S_10 extends Query<any, any, {}, any, 'find'>
    ? S_10
    : Query<any, any, {}, any, 'find'>
    >(
    method:
    | MongooseQueryOrDocumentMiddleware
    | MongooseQueryOrDocumentMiddleware[]
    | RegExp,
    fn: PostMiddlewareFunction<T_11, QueryResultType<T_11>>,
    options?: SchemaPostOptions & { document: false; query: true }
    ): ClassDecorator;
    <
    S_11 extends unknown,
    T_12 = S_11 extends Query<any, any, {}, any, 'find'>
    ? S_11
    : S_11 extends Document<any, any, any>
    ? S_11
    : HydratedDocument<any, any>
    >(
    method:
    | MongooseQueryOrDocumentMiddleware
    | MongooseQueryOrDocumentMiddleware[]
    | RegExp,
    fn: ErrorHandlingMiddlewareFunction<T_12>,
    options?: SchemaPostOptions & { document: true; query: true }
    ): ClassDecorator;
    <T_13 extends Aggregate<any>>(
    method: 'aggregate' | RegExp,
    fn: PostMiddlewareFunction<T_13, AggregateExtract<T_13>[]>,
    options?: SchemaPostOptions
    ): ClassDecorator;
    <
    S_12 extends unknown,
    T_14 = S_12 extends Model<any, {}, {}, {}, any, any> ? S_12 : any
    >(
    method: 'insertMany' | RegExp,
    fn: PostMiddlewareFunction<T_14, T_14>,
    options?: SchemaPostOptions
    ): ClassDecorator;
    };

      variable Post

      const Post: {
      <
      S extends unknown,
      T = S extends Query<any, any, {}, any, 'find'>
      ? S
      : Query<any, any, {}, any, 'find'>
      >(
      method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp,
      fn: ErrorHandlingMiddlewareFunction<T>,
      options: SchemaPostOptions & { errorHandler: true }
      ): ClassDecorator;
      <
      S_1 extends unknown,
      T_1 = S_1 extends Document<any, any, any> ? S_1 : HydratedDocument<any, any>
      >(
      method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp,
      fn: ErrorHandlingMiddlewareFunction<T_1>,
      options: SchemaPostOptions & { errorHandler: true }
      ): ClassDecorator;
      <T_2 extends Aggregate<any>>(
      method: 'aggregate' | RegExp,
      fn: ErrorHandlingMiddlewareFunction<T_2, any[]>,
      options: SchemaPostOptions & { errorHandler: true }
      ): ClassDecorator;
      <
      S_2 extends unknown,
      T_3 = S_2 extends Model<any, {}, {}, {}, any, any> ? S_2 : any
      >(
      method: 'insertMany' | RegExp,
      fn: ErrorHandlingMiddlewareFunction<T_3>,
      options: SchemaPostOptions & { errorHandler: true }
      ): ClassDecorator;
      <S_3 extends never, T_4 = S_3>(
      method:
      | MongooseQueryOrDocumentMiddleware
      | MongooseQueryOrDocumentMiddleware[]
      | RegExp,
      fn: PostMiddlewareFunction<T_4, T_4>,
      options?: SchemaPostOptions & { document: false; query: false }
      ): ClassDecorator;
      <S_4 extends never, T_5 = S_4>(
      method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
      fn: PostMiddlewareFunction<T_5, T_5>,
      options?: SchemaPostOptions & { document: boolean; query: false }
      ): ClassDecorator;
      <S_5 extends never, T_6 = S_5>(
      method:
      | MongooseDistinctDocumentMiddleware
      | MongooseDistinctDocumentMiddleware[],
      fn: PostMiddlewareFunction<T_6, T_6>,
      options?: SchemaPostOptions & { document: false; query: true }
      ): ClassDecorator;
      <
      S_6 extends unknown,
      T_7 = S_6 extends Document<any, any, any> ? S_6 : HydratedDocument<any, any>
      >(
      method:
      | MongooseDistinctDocumentMiddleware
      | MongooseDistinctDocumentMiddleware[],
      fn: PostMiddlewareFunction<T_7, T_7>,
      options?: SchemaPostOptions
      ): ClassDecorator;
      <
      S_7 extends unknown,
      T_8 = S_7 extends Document<any, any, any> ? S_7 : HydratedDocument<any, any>
      >(
      method:
      | MongooseQueryOrDocumentMiddleware
      | MongooseQueryOrDocumentMiddleware[]
      | RegExp,
      fn: PostMiddlewareFunction<T_8, T_8>,
      options?: SchemaPostOptions & { document: true; query: false }
      ): ClassDecorator;
      <
      S_8 extends unknown,
      T_9 = S_8 extends Query<any, any, {}, any, 'find'>
      ? S_8
      : Query<any, any, {}, any, 'find'>
      >(
      method: MongooseDefaultQueryMiddleware | MongooseDefaultQueryMiddleware[],
      fn: PostMiddlewareFunction<T_9, QueryResultType<T_9>>
      ): ClassDecorator;
      <
      S_9 extends unknown,
      T_10 = S_9 extends Query<any, any, {}, any, 'find'>
      ? S_9
      : Query<any, any, {}, any, 'find'>
      >(
      method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
      fn: PostMiddlewareFunction<T_10, QueryResultType<T_10>>,
      options?: SchemaPostOptions
      ): ClassDecorator;
      <
      S_10 extends unknown,
      T_11 = S_10 extends Query<any, any, {}, any, 'find'>
      ? S_10
      : Query<any, any, {}, any, 'find'>
      >(
      method:
      | MongooseQueryOrDocumentMiddleware
      | MongooseQueryOrDocumentMiddleware[]
      | RegExp,
      fn: PostMiddlewareFunction<T_11, QueryResultType<T_11>>,
      options?: SchemaPostOptions & { document: false; query: true }
      ): ClassDecorator;
      <
      S_11 extends unknown,
      T_12 = S_11 extends Query<any, any, {}, any, 'find'>
      ? S_11
      : S_11 extends Document<any, any, any>
      ? S_11
      : HydratedDocument<any, any>
      >(
      method:
      | MongooseQueryOrDocumentMiddleware
      | MongooseQueryOrDocumentMiddleware[]
      | RegExp,
      fn: ErrorHandlingMiddlewareFunction<T_12>,
      options?: SchemaPostOptions & { document: true; query: true }
      ): ClassDecorator;
      <T_13 extends Aggregate<any>>(
      method: 'aggregate' | RegExp,
      fn: PostMiddlewareFunction<T_13, AggregateExtract<T_13>[]>,
      options?: SchemaPostOptions
      ): ClassDecorator;
      <
      S_12 extends unknown,
      T_14 = S_12 extends Model<any, {}, {}, {}, any, any> ? S_12 : any
      >(
      method: 'insertMany' | RegExp,
      fn: PostMiddlewareFunction<T_14, T_14>,
      options?: SchemaPostOptions
      ): ClassDecorator;
      };

        variable pre

        const pre: {
        <S extends never, T = S>(
        method: 'save',
        fn: PreSaveMiddlewareFunction<T>,
        options?: SchemaPreOptions & { document: false; query: boolean }
        ): ClassDecorator;
        <S_1 extends never, T_1 = S_1>(
        method:
        | MongooseQueryOrDocumentMiddleware
        | MongooseQueryOrDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_1>,
        options?: SchemaPreOptions & { document: false; query: false }
        ): ClassDecorator;
        <S_2 extends never, T_2 = S_2>(
        method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
        fn: PreMiddlewareFunction<T_2>,
        options?: SchemaPreOptions & { document: boolean; query: false }
        ): ClassDecorator;
        <S_3 extends never, T_3 = S_3>(
        method:
        | MongooseDistinctDocumentMiddleware
        | MongooseDistinctDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_3>,
        options?: SchemaPreOptions & { document: false; query: boolean }
        ): ClassDecorator;
        <
        S_4 extends unknown,
        T_4 = S_4 extends Query<any, any, {}, any, 'find'>
        ? S_4
        : S_4 extends Document<any, any, any>
        ? S_4
        : HydratedDocument<any, any>
        >(
        method:
        | MongooseQueryAndDocumentMiddleware
        | MongooseQueryAndDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_4>,
        options?: SchemaPreOptions & { document: true; query: true }
        ): ClassDecorator;
        <
        S_5 extends unknown,
        T_5 = S_5 extends Document<any, any, any> ? S_5 : HydratedDocument<any, any>
        >(
        method: 'save',
        fn: PreSaveMiddlewareFunction<T_5>,
        options?: SchemaPreOptions
        ): ClassDecorator;
        <
        S_6 extends unknown,
        T_6 = S_6 extends Document<any, any, any> ? S_6 : HydratedDocument<any, any>
        >(
        method:
        | MongooseDistinctDocumentMiddleware
        | MongooseDistinctDocumentMiddleware[],
        fn: PreMiddlewareFunction<T_6>,
        options?: SchemaPreOptions
        ): ClassDecorator;
        <
        S_7 extends unknown,
        T_7 = S_7 extends Document<any, any, any> ? S_7 : HydratedDocument<any, any>
        >(
        method:
        | MongooseQueryAndDocumentMiddleware
        | MongooseQueryAndDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_7>,
        options?: SchemaPreOptions & { document: true }
        ): ClassDecorator;
        <
        S_8 extends unknown,
        T_8 = S_8 extends Document<any, any, any> ? S_8 : HydratedDocument<any, any>
        >(
        method:
        | MongooseQueryOrDocumentMiddleware
        | MongooseQueryOrDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_8>,
        options?: SchemaPreOptions & { document: true; query: false }
        ): ClassDecorator;
        <
        S_9 extends unknown,
        T_9 = S_9 extends Query<any, any, {}, any, 'find'>
        ? S_9
        : Query<any, any, {}, any, 'find'>
        >(
        method: MongooseDefaultQueryMiddleware | MongooseDefaultQueryMiddleware[],
        fn: PreMiddlewareFunction<T_9>
        ): ClassDecorator;
        <
        S_10 extends unknown,
        T_10 = S_10 extends Query<any, any, {}, any, 'find'>
        ? S_10
        : Query<any, any, {}, any, 'find'>
        >(
        method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
        fn: PreMiddlewareFunction<T_10>,
        options?: SchemaPreOptions
        ): ClassDecorator;
        <
        S_11 extends unknown,
        T_11 = S_11 extends Query<any, any, {}, any, 'find'>
        ? S_11
        : Query<any, any, {}, any, 'find'>
        >(
        method:
        | MongooseQueryOrDocumentMiddleware
        | MongooseQueryOrDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_11>,
        options?: SchemaPreOptions & { document: false; query: true }
        ): ClassDecorator;
        <
        S_12 extends unknown,
        T_12 = S_12 extends Query<any, any, {}, any, 'find'>
        ? S_12
        : S_12 extends Document<any, any, any>
        ? S_12
        : HydratedDocument<any, any>
        >(
        method:
        | MongooseQueryOrDocumentMiddleware
        | MongooseQueryOrDocumentMiddleware[]
        | RegExp,
        fn: PreMiddlewareFunction<T_12>,
        options?: SchemaPreOptions & { document: true; query: true }
        ): ClassDecorator;
        <T_13 extends Aggregate<any>>(
        method: 'aggregate' | RegExp,
        fn: PreMiddlewareFunction<T_13>,
        options?: SchemaPreOptions
        ): ClassDecorator;
        <
        S_13 extends unknown,
        T_14 = S_13 extends Model<any, {}, {}, {}, any, any> ? S_13 : any
        >(
        method: 'insertMany' | RegExp,
        fn: (
        this: T_14,
        next: (err?: CallbackError) => void,
        docs: any | Array<any>,
        options?: InsertManyOptions & { lean?: boolean }
        ) => void | Promise<void>,
        options?: SchemaPreOptions
        ): ClassDecorator;
        };

          variable Pre

          const Pre: {
          <S extends never, T = S>(
          method: 'save',
          fn: PreSaveMiddlewareFunction<T>,
          options?: SchemaPreOptions & { document: false; query: boolean }
          ): ClassDecorator;
          <S_1 extends never, T_1 = S_1>(
          method:
          | MongooseQueryOrDocumentMiddleware
          | MongooseQueryOrDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_1>,
          options?: SchemaPreOptions & { document: false; query: false }
          ): ClassDecorator;
          <S_2 extends never, T_2 = S_2>(
          method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
          fn: PreMiddlewareFunction<T_2>,
          options?: SchemaPreOptions & { document: boolean; query: false }
          ): ClassDecorator;
          <S_3 extends never, T_3 = S_3>(
          method:
          | MongooseDistinctDocumentMiddleware
          | MongooseDistinctDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_3>,
          options?: SchemaPreOptions & { document: false; query: boolean }
          ): ClassDecorator;
          <
          S_4 extends unknown,
          T_4 = S_4 extends Query<any, any, {}, any, 'find'>
          ? S_4
          : S_4 extends Document<any, any, any>
          ? S_4
          : HydratedDocument<any, any>
          >(
          method:
          | MongooseQueryAndDocumentMiddleware
          | MongooseQueryAndDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_4>,
          options?: SchemaPreOptions & { document: true; query: true }
          ): ClassDecorator;
          <
          S_5 extends unknown,
          T_5 = S_5 extends Document<any, any, any> ? S_5 : HydratedDocument<any, any>
          >(
          method: 'save',
          fn: PreSaveMiddlewareFunction<T_5>,
          options?: SchemaPreOptions
          ): ClassDecorator;
          <
          S_6 extends unknown,
          T_6 = S_6 extends Document<any, any, any> ? S_6 : HydratedDocument<any, any>
          >(
          method:
          | MongooseDistinctDocumentMiddleware
          | MongooseDistinctDocumentMiddleware[],
          fn: PreMiddlewareFunction<T_6>,
          options?: SchemaPreOptions
          ): ClassDecorator;
          <
          S_7 extends unknown,
          T_7 = S_7 extends Document<any, any, any> ? S_7 : HydratedDocument<any, any>
          >(
          method:
          | MongooseQueryAndDocumentMiddleware
          | MongooseQueryAndDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_7>,
          options?: SchemaPreOptions & { document: true }
          ): ClassDecorator;
          <
          S_8 extends unknown,
          T_8 = S_8 extends Document<any, any, any> ? S_8 : HydratedDocument<any, any>
          >(
          method:
          | MongooseQueryOrDocumentMiddleware
          | MongooseQueryOrDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_8>,
          options?: SchemaPreOptions & { document: true; query: false }
          ): ClassDecorator;
          <
          S_9 extends unknown,
          T_9 = S_9 extends Query<any, any, {}, any, 'find'>
          ? S_9
          : Query<any, any, {}, any, 'find'>
          >(
          method: MongooseDefaultQueryMiddleware | MongooseDefaultQueryMiddleware[],
          fn: PreMiddlewareFunction<T_9>
          ): ClassDecorator;
          <
          S_10 extends unknown,
          T_10 = S_10 extends Query<any, any, {}, any, 'find'>
          ? S_10
          : Query<any, any, {}, any, 'find'>
          >(
          method: MongooseDistinctQueryMiddleware | MongooseDistinctQueryMiddleware[],
          fn: PreMiddlewareFunction<T_10>,
          options?: SchemaPreOptions
          ): ClassDecorator;
          <
          S_11 extends unknown,
          T_11 = S_11 extends Query<any, any, {}, any, 'find'>
          ? S_11
          : Query<any, any, {}, any, 'find'>
          >(
          method:
          | MongooseQueryOrDocumentMiddleware
          | MongooseQueryOrDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_11>,
          options?: SchemaPreOptions & { document: false; query: true }
          ): ClassDecorator;
          <
          S_12 extends unknown,
          T_12 = S_12 extends Query<any, any, {}, any, 'find'>
          ? S_12
          : S_12 extends Document<any, any, any>
          ? S_12
          : HydratedDocument<any, any>
          >(
          method:
          | MongooseQueryOrDocumentMiddleware
          | MongooseQueryOrDocumentMiddleware[]
          | RegExp,
          fn: PreMiddlewareFunction<T_12>,
          options?: SchemaPreOptions & { document: true; query: true }
          ): ClassDecorator;
          <T_13 extends Aggregate<any>>(
          method: 'aggregate' | RegExp,
          fn: PreMiddlewareFunction<T_13>,
          options?: SchemaPreOptions
          ): ClassDecorator;
          <
          S_13 extends unknown,
          T_14 = S_13 extends Model<any, {}, {}, {}, any, any> ? S_13 : any
          >(
          method: 'insertMany' | RegExp,
          fn: (
          this: T_14,
          next: (err?: CallbackError) => void,
          docs: any | Array<any>,
          options?: InsertManyOptions & { lean?: boolean }
          ) => void | Promise<void>,
          options?: SchemaPreOptions
          ): ClassDecorator;
          };

            Functions

            function addModelToTypegoose

            addModelToTypegoose: <
            U extends AnyParamConstructor<any>,
            QueryHelpers = BeAnObject
            >(
            model: mongoose.Model<any>,
            cl: U,
            options?: {
            existingMongoose?: mongoose.Mongoose;
            existingConnection?: any;
            disableCaching?: boolean;
            }
            ) => ReturnModelType<U, QueryHelpers>;
            • Add a Class-Model Pair to the Typegoose Cache This can be used to add custom Models to Typegoose, with the type information of "cl" Note: no guarrantee that the type information is fully correct when used manually

              Parameter model

              The Model to store

              Parameter cl

              The Class to store

              Parameter options

              Overwrite existingMongoose or existingConnection

              Example 1

              class ClassName {}
              const schema = buildSchema(ClassName);
              // modifications to the schema can be done
              const model = addModelToTypegoose(mongoose.model("Name", schema), ClassName);

            function buildSchema

            buildSchema: <U extends AnyParamConstructor<any>>(
            cl: U,
            options?: IModelOptions
            ) => mongoose.Schema<any>;
            • Generates a Mongoose schema out of class props, iterating through all parents

              Parameter cl

              The Class to build a Schema from

              Parameter options

              Overwrite Options, like for naming or general SchemaOptions the class gets compiled with

              Returns

              Returns the Build Schema

              Example 1

              class ClassName {}
              const NameSchema = buildSchema(ClassName);
              const NameModel = mongoose.model("Name", NameSchema);

            function deleteModel

            deleteModel: (name: string) => void;
            • Deletes a existing model so that it can be overwritten with another model (deletes from mongoose.connection and typegoose models cache and typegoose constructors cache)

              Parameter name

              The Model's mongoose name

              Example 1

              class ClassName {}
              const NameModel = getModelForClass(ClassName);
              deleteModel("ClassName");

            function deleteModelWithClass

            deleteModelWithClass: <U extends AnyParamConstructor<any>>(cl: U) => void;
            • Delete a model, with the given class Same as "deleteModel", only that it can be done with the class instead of the name

              Parameter cl

              The Class to delete the model from

              Example 1

              class ClassName {}
              const NameModel = getModelForClass(ClassName);
              deleteModelWithClass(ClassName);

            function getClass

            getClass: (
            input:
            | mongoose.Document
            | IObjectWithTypegooseFunction
            | { typegooseName: string }
            | string
            | any
            ) => NewableFunction | undefined;
            • Get the Class for a number of inputs

              Parameter input

              The Input to fetch the class from

            function getDiscriminatorModelForClass

            getDiscriminatorModelForClass: {
            <U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
            from: mongoose.Model<any, any, any, any>,
            cl: U,
            options?: IModelOptions
            ): ReturnModelType<U, QueryHelpers>;
            <U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
            from: mongoose.Model<any, any, any, any>,
            cl: U,
            value?: string
            ): any;
            <U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject>(
            from: mongoose.Model<any, any, any, any>,
            cl: U,
            value?: string,
            options?: IModelOptions
            ): any;
            };
            • Build a Model from the given Class and add it as a discriminator onto "from"

              Parameter from

              The Model to add the new discriminator model to

              Parameter cl

              The Class to make a discriminator model from

              Parameter options

              Overwrite ModelOptions (Merged with ModelOptions from class)

              Example 1

              class Main {
              @prop({ ref: () => BaseDiscriminator })
              public discriminators?: Ref<BaseDiscriminator>;
              }
              class BaseDiscriminator {
              @prop()
              public propertyOnAllDiscriminators?: string;
              }
              class AnotherDiscriminator {
              @prop()
              public someValue?: string;
              }
              const MainModel = getModelForClass(Main);
              const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
              const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
              // add other discriminator models the same way as "AnotherDiscriminatorModel"
            • Build a Model from the given Class and add it as a discriminator onto "from"

              Parameter from

              The Model to add the new discriminator model to

              Parameter cl

              The Class to make a discriminator model from

              Parameter value

              The Identifier to use to differentiate documents (default: cl.name)

              Example 1

              class Main {
              @prop({ ref: () => BaseDiscriminator })
              public discriminators?: Ref<BaseDiscriminator>;
              }
              class BaseDiscriminator {
              @prop()
              public propertyOnAllDiscriminators?: string;
              }
              class AnotherDiscriminator {
              @prop()
              public someValue?: string;
              }
              const MainModel = getModelForClass(Main);
              const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
              const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
              // add other discriminator models the same way as "AnotherDiscriminatorModel"
            • Build a Model from the given Class and add it as a discriminator onto "from"

              Parameter from

              The Model to add the new discriminator model to

              Parameter cl

              The Class to make a discriminator model from

              Parameter value

              The Identifier to use to differentiate documents (default: cl.name)

              Parameter options

              Overwrite ModelOptions (Merged with ModelOptions from class)

              Example 1

              class Main {
              @prop({ ref: () => BaseDiscriminator })
              public discriminators?: Ref<BaseDiscriminator>;
              }
              class BaseDiscriminator {
              @prop()
              public propertyOnAllDiscriminators?: string;
              }
              class AnotherDiscriminator {
              @prop()
              public someValue?: string;
              }
              const MainModel = getModelForClass(Main);
              const BaseDiscriminatorModel = getModelFroClass(BaseDiscriminator);
              const AnotherDiscriminatorModel = getDiscriminatorModelForClass(BaseDiscriminatorModel, AnotherDiscriminator);
              // add other discriminator models the same way as "AnotherDiscriminatorModel"

            function getModelForClass

            getModelForClass: <
            U extends AnyParamConstructor<any>,
            QueryHelpers = BeAnObject
            >(
            cl: U,
            options?: IModelOptions
            ) => ReturnModelType<U, QueryHelpers>;
            • Build a Model From a Class

              Parameter cl

              The Class to build a Model from

              Parameter options

              Overwrite Options, like for naming or general SchemaOptions the class gets compiled with

              Returns

              The finished Model

              Example 1

              class ClassName {}
              const NameModel = getModelForClass(ClassName);

              Modifiers

              • @public

            function getModelWithString

            getModelWithString: <
            U extends AnyParamConstructor<any>,
            QueryHelpers = BeAnObject
            >(
            key: string
            ) => undefined | ReturnModelType<U, QueryHelpers>;
            • Get Model from internal cache

              Parameter key

              Model's name key

              Example 1

              class ClassName {}
              getModelForClass(ClassName); // build the model
              const NameModel = getModelWithString<typeof ClassName>("ClassName");

            function getName

            getName: <U extends AnyParamConstructor<any>>(
            cl: U,
            overwriteNaming?: INamingOptions
            ) => string;
            • Get the Class's final name (combines all available options to generate a name)

              Parameter cl

              The Class to get the name for

              Parameter overwriteNaming

              Overwrite naming options used for generating the name

            function index

            index: (
            fields: mongoose.IndexDefinition,
            options?: mongoose.IndexOptions
            ) => ClassDecorator;
            • Defines a index for this Class which will then be added to the Schema.

              Parameter fields

              Which fields to index (if multiple fields are set, it will be a compound index)

              Parameter options

              Options to pass to MongoDB driver's createIndex() function

              Example 1

              Example:

              @index({ article: 1, user: 1 }, { unique: true })
              class ClassName {}

            function Index

            Index: (
            fields: mongoose.IndexDefinition,
            options?: mongoose.IndexOptions
            ) => ClassDecorator;
            • Defines a index for this Class which will then be added to the Schema.

              Parameter fields

              Which fields to index (if multiple fields are set, it will be a compound index)

              Parameter options

              Options to pass to MongoDB driver's createIndex() function

              Example 1

              Example:

              @index({ article: 1, user: 1 }, { unique: true })
              class ClassName {}

            function isDocument

            isDocument: <T, S extends mongoose.RefType>(
            doc: Ref<T, S> | null | undefined
            ) => doc is any;
            • Check if the given document is populated

              Parameter doc

              The Ref with uncertain type

            function isDocumentArray

            isDocumentArray: {
            <T, S extends mongoose.RefType>(
            docs: mongoose.Types.Array<Ref<T, S>> | null | undefined
            ): docs is mongoose.Types.Array<any>;
            <T, S extends mongoose.RefType>(
            docs: mongoose.PopulatedDoc<any, RawId>[]
            ): docs is any[];
            };
            • Check if the given array is fully populated Only returns "true" if all members in the array are populated

              Parameter docs

              The Array of Refs with uncertain type

            function isModel

            isModel: (model: any) => model is mongoose.Model<any>;
            • Check if the input is a mongoose.Model

              Parameter model

              The Value to check

            function isRefType

            isRefType: <T, S extends mongoose.RefType>(
            doc: Ref<T, S> | null | undefined,
            refType: AllowedRefTypes
            ) => doc is NonNullable<S>;
            • Check if the document is of type "refType"

              Parameter doc

              The Ref with uncretain type

              Parameter refType

              The Expected Reference Type (this is required because this type is only known at compile time, not at runtime)

            function isRefTypeArray

            isRefTypeArray: {
            <T, S extends mongoose.RefType>(
            docs: mongoose.Types.Array<Ref<T, S>> | null | undefined,
            refType: AllowedRefTypes
            ): docs is mongoose.Types.Array<NonNullable<S>>;
            <T, S extends mongoose.RefType>(
            docs: mongoose.PopulatedDoc<any, RawId>[],
            refType: any
            ): docs is NonNullable<S>[];
            };
            • Check if the array is fully of type "refType" Only returns "true" if all members in the array are of type "refType"

              Parameter docs

              The Ref with uncretain type

              Parameter refType

              The Expected Reference Type (this is required because this type is only known at compile time, not at runtime)

            function modelOptions

            modelOptions: (options: IModelOptions) => ClassDecorator;
            • Define Options for the Class

              Parameter options

              The Options to set

              Example 1

              Example:

              @modelOptions({ schemaOptions: { timestamps: true } })
              class ClassName {}
              // The default Class "TimeStamps" can be used for type information and options already set

            function ModelOptions

            ModelOptions: (options: IModelOptions) => ClassDecorator;
            • Define Options for the Class

              Parameter options

              The Options to set

              Example 1

              Example:

              @modelOptions({ schemaOptions: { timestamps: true } })
              class ClassName {}
              // The default Class "TimeStamps" can be used for type information and options already set

            function plugin

            plugin: <TFunc extends Func, TParams = Parameters<TFunc>[1]>(
            mongoosePlugin: TFunc,
            options?: TParams
            ) => ClassDecorator;
            • Add a mongoose Middleware-Plugin

              Parameter mongoosePlugin

              The Plugin to plug-in

              Parameter options

              Options for the Plugin, if any

              Example 1

              Example:

              @plugin(pluginFunctionHere, { optionsHere: true })
              class ClassName {}

            function Plugins

            Plugins: <TFunc extends Func, TParams = Parameters<TFunc>[1]>(
            mongoosePlugin: TFunc,
            options?: TParams
            ) => ClassDecorator;
            • Add a mongoose Middleware-Plugin

              Parameter mongoosePlugin

              The Plugin to plug-in

              Parameter options

              Options for the Plugin, if any

              Example 1

              Example:

              @plugin(pluginFunctionHere, { optionsHere: true })
              class ClassName {}

            function prop

            prop: (
            options?:
            | BasePropOptions
            | ArrayPropOptions
            | MapPropOptions
            | PropOptionsForNumber
            | PropOptionsForString
            | VirtualOptions,
            kind?: PropType
            ) => PropertyDecorator;
            • Set Property Options for the property below

              Parameter options

              The Options to Set

              Parameter kind

              Overwrite auto-inferred PropType

              Example 1

              class ClassName {
              @prop()
              public someProp?: string;
              @prop({ type: () => [String] })
              public someArrayProp?: string[];
              @prop({ type: () => String })
              public someMapProp?: Map<string, string>;
              }

            function Prop

            Prop: (
            options?:
            | BasePropOptions
            | ArrayPropOptions
            | MapPropOptions
            | PropOptionsForNumber
            | PropOptionsForString
            | VirtualOptions,
            kind?: PropType
            ) => PropertyDecorator;
            • Set Property Options for the property below

              Parameter options

              The Options to Set

              Parameter kind

              Overwrite auto-inferred PropType

              Example 1

              class ClassName {
              @prop()
              public someProp?: string;
              @prop({ type: () => [String] })
              public someArrayProp?: string[];
              @prop({ type: () => String })
              public someMapProp?: Map<string, string>;
              }

            function queryMethod

            queryMethod: <QueryHelpers, U extends AnyParamConstructor<any>>(
            func: (
            this: mongoose.QueryWithHelpers<S, S, QueryHelpers, InstanceType<T>>,
            ...params: any[]
            ) => Query<any, any>
            ) => ClassDecorator;
            • Adds a query method to the Class which will then be added to the Schema.

              Parameter func

              The Query Method to add

              Example 1

              interface FindHelpers {
              findByTitle: AsQueryMethod<typeof findByTitle>;
              }
              function findByTitle(this: ReturnModelType<typeof Event, FindHelpers>, title: string) {
              return this.find({ title });
              }
              @queryMethod(findByTitle)
              class Event {
              @prop()
              public title: string;
              }
              const EventModel = getModelForClass<typeof Event, FindHelpers>(Event);

            function QueryMethod

            QueryMethod: <QueryHelpers, U extends AnyParamConstructor<any>>(
            func: (
            this: mongoose.QueryWithHelpers<S, S, QueryHelpers, InstanceType<T>>,
            ...params: any[]
            ) => Query<any, any>
            ) => ClassDecorator;
            • Adds a query method to the Class which will then be added to the Schema.

              Parameter func

              The Query Method to add

              Example 1

              interface FindHelpers {
              findByTitle: AsQueryMethod<typeof findByTitle>;
              }
              function findByTitle(this: ReturnModelType<typeof Event, FindHelpers>, title: string) {
              return this.find({ title });
              }
              @queryMethod(findByTitle)
              class Event {
              @prop()
              public title: string;
              }
              const EventModel = getModelForClass<typeof Event, FindHelpers>(Event);

            function searchIndex

            searchIndex: (description: mongoose.SearchIndexDescription) => ClassDecorator;
            • Defines a search index for this Class which will then be added to the Schema.

              Parameter description

              The description of the search index to add.

              Remarks

              Search indices are only supported when connected to MongoDB Atlas.

              Example 1

              Example:

              @searchIndex({ name: 'descriptionIndex', definition: { mappings: { dynamic: true }}})
              class ClassName {}

            function SearchIndex

            SearchIndex: (description: mongoose.SearchIndexDescription) => ClassDecorator;
            • Defines a search index for this Class which will then be added to the Schema.

              Parameter description

              The description of the search index to add.

              Remarks

              Search indices are only supported when connected to MongoDB Atlas.

              Example 1

              Example:

              @searchIndex({ name: 'descriptionIndex', definition: { mappings: { dynamic: true }}})
              class ClassName {}

            function setGlobalOptions

            setGlobalOptions: (options: IGlobalOptions) => void;
            • Set Typegoose's global Options

            function setLogLevel

            setLogLevel: (level: logger.LogLevelDesc, persist?: boolean | undefined) => void;

              Classes

              class Passthrough

              class Passthrough {}
              • Use this class if raw mongoose for a path is wanted It is still recommended to use the typegoose classes directly

                Example 1

                class Dummy {
                @prop({ type: () => new Passthrough({ somePath: String }) })
                public somepath: { somePath: string };
                }
                class Dummy {
                @prop({ type: () => new Passthrough({ somePath: String }, true) })
                public somepath: { somePath: string };
                }

                See Also

                • Using Passthrough, the paths created will also result as an Schema (since mongoose 6.0), see

              constructor

              constructor(raw: any, direct?: boolean);
              • Use this like new mongoose.Schema()

                Parameter raw

                The Schema definition

                Parameter direct

                Directly insert "raw", instead of using "type" (this will not apply any other inner options)

              property direct

              direct: boolean;

                property raw

                raw: any;

                  Enums

                  enum PropType

                  enum PropType {
                  ARRAY = 0,
                  MAP = 1,
                  NONE = 2,
                  }
                  • This Enum is meant for baseProp to decide for different props (like if it is an arrayProp or prop or mapProp)

                  member ARRAY

                  ARRAY = 0

                    member MAP

                    MAP = 1

                      member NONE

                      NONE = 2

                        enum Severity

                        enum Severity {
                        ALLOW = 0,
                        WARN = 1,
                        ERROR = 2,
                        }
                        • Severity levels for soft-warnings

                        member ALLOW

                        ALLOW = 0

                          member ERROR

                          ERROR = 2

                            member WARN

                            WARN = 1

                              Type Aliases

                              type ArraySubDocumentType

                              type ArraySubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<
                              T,
                              QueryHelpers
                              > &
                              mongoose.Types.ArraySubdocument;
                              • Get the Type of an instance of a SubDocument that exists within an array, with Class properties

                              type DocumentType

                              type DocumentType<T, QueryHelpers = BeAnObject> = mongoose.Document<
                              unknown,
                              QueryHelpers,
                              T
                              > &
                              mongoose.Require_id<T> &
                              IObjectWithTypegooseFunction;
                              • Get the Type of an instance of a Document with Class properties

                                Example 1

                                class ClassName {
                                @prop()
                                public someProperty: string;
                                }
                                const NameModel = getModelForClass(ClassName);
                                const doc: DocumentType<ClassName> = await NameModel.create({});

                              type Ref

                              type Ref<
                              PopulatedType,
                              RawId extends mongoose.RefType = PopulatedType extends {
                              _id?: mongoose.RefType;
                              }
                              ? NonNullable<PopulatedType['_id']>
                              : mongoose.Types.ObjectId
                              > = mongoose.PopulatedDoc<DocumentType<PopulatedType>, RawId>;
                              • Reference another Model

                              type ReturnModelType

                              type ReturnModelType<
                              U extends AnyParamConstructor<any>,
                              QueryHelpers = BeAnObject
                              > = ModelType<InstanceType<U>, QueryHelpers> & U;
                              • The Type for Models used in typegoose, mostly returned by "getModelForClass" and "addModelToTypegoose"

                                Example 1

                                const Model: ReturnModelType<typeof YourClass, YourClassQueryHelper> = mongoose.model("YourClass", YourClassSchema);

                              type SubDocumentType

                              type SubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<T, QueryHelpers> &
                              mongoose.Types.Subdocument;
                              • Get the Type of an instance of a SubDocument with Class properties

                              Namespaces

                              namespace defaultClasses

                              module 'lib/defaultClasses.d.ts' {}
                              • This Interface can be used when "_id" and "id" need to be defined in types

                              class TimeStamps

                              abstract class TimeStamps {}

                                property createdAt

                                createdAt?: Date;

                                  property updatedAt

                                  updatedAt?: Date;

                                    interface Base

                                    interface Base<IDType extends RefType = Types.ObjectId> {}
                                    • This Interface can be used when "_id" and "id" need to be defined in types

                                    property id

                                    id: string;
                                    • This getter/setter doesn't exist if "schemaOptions.id" being set to "false"

                                    namespace errors

                                    module 'lib/internal/errors.d.ts' {}
                                    • Not All Virtual Populate Elements Error

                                    class AssertionFallbackError

                                    class AssertionFallbackError extends Error {}

                                      constructor

                                      constructor();

                                        class CacheDisabledError

                                        class CacheDisabledError extends TypeError {}

                                          constructor

                                          constructor(where: string);

                                            class CannotBeSymbolError

                                            class CannotBeSymbolError extends Error {}

                                              constructor

                                              constructor(name: string, key: string | symbol);

                                                class DuplicateOptionsError

                                                class DuplicateOptionsError extends TypeError {}

                                                  constructor

                                                  constructor(duplicateAt: string[]);

                                                    class ExpectedTypeError

                                                    class ExpectedTypeError extends TypeError {}

                                                      constructor

                                                      constructor(optionName: string, expected: string, got: {});

                                                        class FunctionCalledMoreThanSupportedError

                                                        class FunctionCalledMoreThanSupportedError extends Error {}

                                                          constructor

                                                          constructor(functionName: string, supported: number, extra: string);

                                                            class InvalidEnumTypeError

                                                            class InvalidEnumTypeError extends TypeError {}

                                                              constructor

                                                              constructor(name: string, key: string, value: {});

                                                                class InvalidOptionsConstructorError

                                                                class InvalidOptionsConstructorError extends TypeError {}

                                                                  constructor

                                                                  constructor(name: string, key: string, type: {});

                                                                    class InvalidPropTypeError

                                                                    class InvalidPropTypeError extends Error {}
                                                                    • Error for when an unknown PropType is passed to an switch, gets thrown in the default case

                                                                    constructor

                                                                    constructor(proptype: {}, name: string, key: string, where: string);

                                                                      class InvalidTypeError

                                                                      class InvalidTypeError extends Error {}

                                                                        constructor

                                                                        constructor(targetName: string, key: string, Type: {});

                                                                          class NoDiscriminatorFunctionError

                                                                          class NoDiscriminatorFunctionError extends Error {}

                                                                            constructor

                                                                            constructor(name: string, key: string);

                                                                              class NotAllVPOPElementsError

                                                                              class NotAllVPOPElementsError extends Error {}
                                                                              • Not All Virtual Populate Elements Error

                                                                              constructor

                                                                              constructor(name: string, key: string);

                                                                                class NotNumberTypeError

                                                                                class NotNumberTypeError extends Error {}

                                                                                  constructor

                                                                                  constructor(targetName: string, key: string, enumKey: string, enumValue: string);

                                                                                    class NotStringTypeError

                                                                                    class NotStringTypeError extends Error {}

                                                                                      constructor

                                                                                      constructor(targetName: string, key: string, enumKey: string, enumValue: string);

                                                                                        class NotValidModelError

                                                                                        class NotValidModelError extends TypeError {}

                                                                                          constructor

                                                                                          constructor(model: {}, where: string);

                                                                                            class NoValidClassError

                                                                                            class NoValidClassError extends TypeError {}

                                                                                              constructor

                                                                                              constructor(value: {});

                                                                                                class OptionDoesNotSupportOptionError

                                                                                                class OptionDoesNotSupportOptionError extends TypeError {}

                                                                                                  constructor

                                                                                                  constructor(
                                                                                                  currentOption: string,
                                                                                                  problemOption: string,
                                                                                                  expected: string,
                                                                                                  provided: string
                                                                                                  );

                                                                                                    class PathNotInSchemaError

                                                                                                    class PathNotInSchemaError extends Error {}

                                                                                                      constructor

                                                                                                      constructor(name: string, key: string);

                                                                                                        class RefOptionIsUndefinedError

                                                                                                        class RefOptionIsUndefinedError extends Error {}

                                                                                                          constructor

                                                                                                          constructor(name: string, key: string);

                                                                                                            class ResolveTypegooseNameError

                                                                                                            class ResolveTypegooseNameError extends ReferenceError {}

                                                                                                              constructor

                                                                                                              constructor(input: {});

                                                                                                                class SelfContainingClassError

                                                                                                                class SelfContainingClassError extends TypeError {}

                                                                                                                  constructor

                                                                                                                  constructor(name: string, key: string);

                                                                                                                    class StringLengthExpectedError

                                                                                                                    class StringLengthExpectedError extends TypeError {}

                                                                                                                      constructor

                                                                                                                      constructor(length: number, got: any, where: string, valueName: string);

                                                                                                                        namespace types

                                                                                                                        module 'lib/types.d.ts' {}
                                                                                                                        • Get the Type of an instance of a Document with Class properties

                                                                                                                          Example 1

                                                                                                                          class ClassName {
                                                                                                                          @prop()
                                                                                                                          public someProperty: string;
                                                                                                                          }
                                                                                                                          const NameModel = getModelForClass(ClassName);
                                                                                                                          const doc: DocumentType<ClassName> = await NameModel.create({});

                                                                                                                        interface ArrayPropOptions

                                                                                                                        interface ArrayPropOptions extends BasePropOptions, InnerOuterOptions {}
                                                                                                                        • Options for Array's

                                                                                                                        property castNonArrays

                                                                                                                        castNonArrays?: boolean;
                                                                                                                        • Set if Non-Array values will be cast to an array

                                                                                                                          NOTE: This option currently only really affects "DocumentArray" and not normal arrays, https://github.com/Automattic/mongoose/issues/10398

                                                                                                                          Example 1

                                                                                                                          new Model({ array: "string" });
                                                                                                                          // will be cast to equal
                                                                                                                          new Model({ array: ["string"] });

                                                                                                                          true

                                                                                                                          See Also

                                                                                                                          • https://mongoosejs.com/docs/api/schemaarray.html#schemaarray_SchemaArray.options

                                                                                                                        property dim

                                                                                                                        dim?: number;
                                                                                                                        • How many dimensions this Array should have (needs to be higher than 0)

                                                                                                                          Note: Custom Typegoose Option 1

                                                                                                                        interface BasePropOptions

                                                                                                                        interface BasePropOptions {}
                                                                                                                        • This Interface for most properties uses "mongoose.SchemaTypeOptions['']", but for some special (or typegoose custom) options, it is not used

                                                                                                                          Example: index is directly from mongoose, where as type is from typegoose

                                                                                                                        property addNullToEnum

                                                                                                                        addNullToEnum?: boolean;
                                                                                                                        • Add "null" to the enum array Note: Custom Typegoose Option

                                                                                                                        property alias

                                                                                                                        alias?: mongoose.SchemaTypeOptions<any>['alias'];
                                                                                                                        • Give the Property an alias in the output

                                                                                                                          Note: you should include the alias as a variable in the class, but not with a prop decorator

                                                                                                                          Example 1

                                                                                                                          class Dummy {
                                                                                                                          @prop({ alias: "helloWorld" })
                                                                                                                          public hello: string; // normal, with @prop
                                                                                                                          public helloWorld: string; // is just for type Completion, will not be included in the DB
                                                                                                                          }

                                                                                                                        property allowMixed

                                                                                                                        allowMixed?: Severity;
                                                                                                                        • Set Custom "warnMixed" Severity for a specific property Overwrites Severity set in "modelOptions" for a specific property Note: Custom Typegoose Option

                                                                                                                        property auto

                                                                                                                        auto?: mongoose.SchemaTypeOptions<any>['auto'];
                                                                                                                        • If true, uses Mongoose's default _id settings. Only allowed for ObjectIds

                                                                                                                          Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions

                                                                                                                        property autopopulate

                                                                                                                        autopopulate?: boolean | Function | KeyStringAny;
                                                                                                                        • This option as only an effect when the plugin mongoose-autopopulate is used

                                                                                                                        property default

                                                                                                                        default?: mongoose.SchemaTypeOptions<any>['default'];
                                                                                                                        • Give the Property a default Value

                                                                                                                        property discriminators

                                                                                                                        discriminators?: NestedDiscriminatorsFunction;
                                                                                                                        • Set the Nested Discriminators

                                                                                                                          Note: "_id: false" as a prop option doesn't work here

                                                                                                                          Note: Custom Typegoose Option

                                                                                                                        property enum

                                                                                                                        enum?:
                                                                                                                        | EnumCombinedType
                                                                                                                        | DeferredFunc<EnumCombinedType>
                                                                                                                        | {
                                                                                                                        values: DeferredFunc<EnumValues>;
                                                                                                                        message?: string;
                                                                                                                        };
                                                                                                                        • Only accept Values from the Enum(|Array)

                                                                                                                        property excludeIndexes

                                                                                                                        excludeIndexes?: mongoose.SchemaTypeOptions<any>['excludeIndexes'];
                                                                                                                        • If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.

                                                                                                                          Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions

                                                                                                                        property expires

                                                                                                                        expires?: mongoose.SchemaTypeOptions<any>['expires'];
                                                                                                                        • Should this property have an "expires" index? https://docs.mongodb.com/manual/tutorial/expire-data

                                                                                                                        property get

                                                                                                                        get?: mongoose.SchemaTypeOptions<any>['get'];
                                                                                                                        • Set a Getter (Non-Virtual) to Post-process your value (when using get/set both are required) Please note that the option type is required, if get/set saves a different value than what is defined

                                                                                                                          Parameter value

                                                                                                                          The Value that needs to get modified

                                                                                                                          Returns

                                                                                                                          The Value, but modified OR anything

                                                                                                                          Example 1

                                                                                                                          function setHello(val: string): string {
                                                                                                                          return val.toLowerCase()
                                                                                                                          }
                                                                                                                          function getHello(val: string): string {
                                                                                                                          return val.toUpperCase();
                                                                                                                          }
                                                                                                                          class Dummy {
                                                                                                                          @prop({ set: setHello, get: getHello }) // many options can be used, like required
                                                                                                                          public hello: string;
                                                                                                                          }

                                                                                                                        property immutable

                                                                                                                        immutable?: mongoose.SchemaTypeOptions<any>['immutable'];
                                                                                                                        • Make a property read-only

                                                                                                                          Example 1

                                                                                                                          class SomeClass {
                                                                                                                          @prop({ immutable: true })
                                                                                                                          public someprop: Readonly<string>;
                                                                                                                          }

                                                                                                                        property index

                                                                                                                        index?: mongoose.SchemaTypeOptions<any>['index'];
                                                                                                                        • Should this property have an index? Note: don't use this if you want to do a compound index https://docs.mongodb.com/manual/indexes

                                                                                                                        property of

                                                                                                                        of?: never;
                                                                                                                        • Use option

                                                                                                                          See Also

                                                                                                                          • https://typegoose.github.io/typegoose/docs/api/decorators/prop#map-options

                                                                                                                          • https://typegoose.github.io/typegoose/docs/api/decorators/prop#proptype

                                                                                                                        property ref

                                                                                                                        ref?:
                                                                                                                        | DeferredFunc<string | AnyParamConstructor<any> | DynamicStringFunc<any>>
                                                                                                                        | string
                                                                                                                        | AnyParamConstructor<any>;
                                                                                                                        • Reference another Document (you should use Ref as Prop type)

                                                                                                                        property refPath

                                                                                                                        refPath?: string;
                                                                                                                        • Take the Path and try to resolve it to a Model

                                                                                                                        property required

                                                                                                                        required?: mongoose.SchemaTypeOptions<any>['required'];
                                                                                                                        • is this value required? false (Implicitly)

                                                                                                                        property select

                                                                                                                        select?: mongoose.SchemaTypeOptions<any>['select'];
                                                                                                                        • include this value? true (Implicitly)

                                                                                                                        property set

                                                                                                                        set?: mongoose.SchemaTypeOptions<any>['set'];
                                                                                                                        • Set a Setter (Non-Virtual) to pre-process your value (when using get/set both are required) Please note that the option type is required, if get/set saves a different value than what is defined

                                                                                                                          Parameter value

                                                                                                                          The Value that needs to get modified

                                                                                                                          Returns

                                                                                                                          The Value, but modified OR anything

                                                                                                                          Example 1

                                                                                                                          function setHello(val: string): string {
                                                                                                                          return val.toLowerCase()
                                                                                                                          }
                                                                                                                          function getHello(val: string): string {
                                                                                                                          return val.toUpperCase();
                                                                                                                          }
                                                                                                                          class Dummy {
                                                                                                                          @prop({ set: setHello, get: getHello }) // many options can be used, like required
                                                                                                                          public hello: string;
                                                                                                                          }

                                                                                                                        property sparse

                                                                                                                        sparse?: mongoose.SchemaTypeOptions<any>['sparse'];
                                                                                                                        • Should this property have a "sparse" index? https://docs.mongodb.com/manual/indexes/#sparse-indexes

                                                                                                                        property subtype

                                                                                                                        subtype?: mongoose.SchemaTypeOptions<any>['subtype'];
                                                                                                                        • The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths

                                                                                                                          Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions

                                                                                                                        property text

                                                                                                                        text?: mongoose.SchemaTypeOptions<any>['text'];
                                                                                                                        • Should this property have a "text" index? https://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-text

                                                                                                                        property transform

                                                                                                                        transform?: mongoose.SchemaTypeOptions<any>['transform'];
                                                                                                                        • Define a transform function for this individual schema type. Only called when calling toJSON() or toObject().

                                                                                                                          Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions

                                                                                                                        property type

                                                                                                                        type?: DeferredFunc<AnyParamConstructor<any>> | DeferredFunc<unknown> | unknown;
                                                                                                                        • This may be needed if get/set is used (this sets the type how it is saved to the DB)

                                                                                                                        property unique

                                                                                                                        unique?: mongoose.SchemaTypeOptions<any>['unique'];
                                                                                                                        • Should this property have a "unique" index? https://docs.mongodb.com/manual/indexes/#unique-indexes

                                                                                                                        property validate

                                                                                                                        validate?: mongoose.SchemaTypeOptions<any>['validate'];
                                                                                                                        • Give a Validator RegExp or Function

                                                                                                                        index signature

                                                                                                                        [extra: string]: any;

                                                                                                                          interface DecoratedPropertyMetadata

                                                                                                                          interface DecoratedPropertyMetadata {}
                                                                                                                          • Type for the Values stored in the Reflection for Properties

                                                                                                                          property key

                                                                                                                          key: string | symbol;
                                                                                                                          • Property name

                                                                                                                          property options

                                                                                                                          options: KeyStringAny;
                                                                                                                          • Prop Options

                                                                                                                          property propType

                                                                                                                          propType?: PropType;
                                                                                                                          • What is it for a prop type?

                                                                                                                          property target

                                                                                                                          target: AnyParamConstructor<any>;
                                                                                                                          • The Target Reflection target for getting metadata from keys

                                                                                                                          interface DiscriminatorObject

                                                                                                                          interface DiscriminatorObject {}

                                                                                                                            property type

                                                                                                                            type: AnyParamConstructor<any>;
                                                                                                                            • The Class to use

                                                                                                                            property value

                                                                                                                            value?: string;
                                                                                                                            • The Name to differentiate between other classes Mongoose JSDOC: [value] the string stored in the discriminatorKey property. If not specified, Mongoose uses the name parameter. {string} The output of "getName"

                                                                                                                            interface EnumObj

                                                                                                                            interface EnumObj {}
                                                                                                                            • Type for the enum object with custom message

                                                                                                                            property message

                                                                                                                            message?: string;

                                                                                                                              property values

                                                                                                                              values: EnumValues | DeferredFunc<EnumValues>;

                                                                                                                                interface GetTypeReturn

                                                                                                                                interface GetTypeReturn {}
                                                                                                                                • The Return Type of "utils.getType"

                                                                                                                                property dim

                                                                                                                                dim: number;

                                                                                                                                  property type

                                                                                                                                  type: unknown;

                                                                                                                                    interface IBuildSchemaOptions

                                                                                                                                    interface IBuildSchemaOptions {}
                                                                                                                                    • Extra options for "_buildSchema" in "schema.ts"

                                                                                                                                    property buildIndexes

                                                                                                                                    buildIndexes?: boolean;
                                                                                                                                    • Add indexes from this class? will be "false" when "ICustomOptions.disableLowerIndexes" is "true" for some upper class true

                                                                                                                                    property buildSearchIndexes

                                                                                                                                    buildSearchIndexes?: boolean;
                                                                                                                                    • Add search indexes from this class? true

                                                                                                                                    interface ICustomOptions

                                                                                                                                    interface ICustomOptions {}
                                                                                                                                    • Typegoose options, mostly for "modelOptions({ options: ICustomOptions })"

                                                                                                                                    property allowMixed

                                                                                                                                    allowMixed?: Severity;
                                                                                                                                    • Allow "mongoose.Schema.Types.Mixed"?

                                                                                                                                    property automaticName

                                                                                                                                    automaticName?: boolean;
                                                                                                                                    • Enable Automatic Name generation of a model Example: class with name of "SomeClass" and option "collection" of "SC"

                                                                                                                                      will generate the name of "SomeClass_SC" false

                                                                                                                                    property customName

                                                                                                                                    customName?: string | CustomNameFunction;
                                                                                                                                    • Set the modelName of the class. If it is a function, the function will be executed. The function will override "automaticName". If "automaticName" is true and "customName" is a string, it sets a *suffix* instead of the whole name. schemaOptions.collection

                                                                                                                                    property disableCaching

                                                                                                                                    disableCaching?: boolean;
                                                                                                                                    • Disable Caching for this Class if defined via @modelOptions, or disable caching for the getModelForClass / buildSchema / getDiscriminatorModelForClass Does NOT overwrite global disabled caching "undefined" and "false" have the same meaning false

                                                                                                                                    property disableLowerIndexes

                                                                                                                                    disableLowerIndexes?: boolean;
                                                                                                                                    • Disable all lower indexes than this class (works like sch.clone().clearIndexes())

                                                                                                                                      This option DOES NOT get inherited false

                                                                                                                                    property discriminators

                                                                                                                                    discriminators?: NestedDiscriminatorsFunction;
                                                                                                                                    • Set the Nested Discriminators on the *base* of the Discriminators

                                                                                                                                      This option can be used over the prop-option to not have to re-define discriminators if used in multiple classes

                                                                                                                                    property enableMergeHooks

                                                                                                                                    enableMergeHooks?: boolean;
                                                                                                                                    • Enable Merging of Hooks Note: only hooks that can be matched against each-other can be de-duplicated If ICustomOptions.enableMergePlugins and ICustomOptions.enableMergeHooks are both "false", then the global plugins will be automatically applied by typegoose, see https://github.com/Automattic/mongoose/issues/12696 false

                                                                                                                                    property enableMergePlugins

                                                                                                                                    enableMergePlugins?: boolean;
                                                                                                                                    • Enable Overwriting of the plugins on the "to-be" discriminator schema with the base schema's Note: this does not actually "merge plugins", it will overwrite the "to-be" discriminator's plugins with the base schema's If ICustomOptions.enableMergePlugins and ICustomOptions.enableMergeHooks are both "false", then the global plugins will be automatically applied by typegoose, see https://github.com/Automattic/mongoose/issues/12696 false

                                                                                                                                    interface IGlobalOptions

                                                                                                                                    interface IGlobalOptions {}

                                                                                                                                      property globalOptions

                                                                                                                                      globalOptions?: ITypegooseOptions;
                                                                                                                                      • Global Options for general Typegoose

                                                                                                                                      property options

                                                                                                                                      options?: ICustomOptions;
                                                                                                                                      • Typegoose Options

                                                                                                                                      property schemaOptions

                                                                                                                                      schemaOptions?: mongoose.SchemaOptions;
                                                                                                                                      • Schema Options that should get applied to all models

                                                                                                                                      interface IHooksArray

                                                                                                                                      interface IHooksArray {}
                                                                                                                                      • Type for the Values stored in the Reflection for Hooks

                                                                                                                                        Example 1

                                                                                                                                        const postHooks: IHooksArray[] = Array.from(Reflect.getMetadata(DecoratorKeys.HooksPost, target) ?? []);

                                                                                                                                      property func

                                                                                                                                      func: Func;
                                                                                                                                      • The Function to add as a hooks

                                                                                                                                      property methods

                                                                                                                                      methods: (string | RegExp)[];
                                                                                                                                      • The Method to where this hook gets triggered

                                                                                                                                      property options

                                                                                                                                      options?: HookOptionsEither;
                                                                                                                                      • Options for Hooks

                                                                                                                                        See Also

                                                                                                                                        • https://mongoosejs.com/docs/middleware.html#naming

                                                                                                                                      interface IIndexArray

                                                                                                                                      interface IIndexArray {}
                                                                                                                                      • Type for the Values stored in the Reflection for Indexes

                                                                                                                                        Example 1

                                                                                                                                        const indices: IIndexArray[] = Reflect.getMetadata(DecoratorKeys.Index, target) || [];

                                                                                                                                      property fields

                                                                                                                                      fields: KeyStringAny;

                                                                                                                                        property options

                                                                                                                                        options?: IndexOptions;

                                                                                                                                          interface IModelOptions

                                                                                                                                          interface IModelOptions {}

                                                                                                                                            property existingConnection

                                                                                                                                            existingConnection?: mongoose.Connection;
                                                                                                                                            • An Existing Connection

                                                                                                                                            property existingMongoose

                                                                                                                                            existingMongoose?: mongoose.Mongoose;
                                                                                                                                            • An Existing Mongoose Connection

                                                                                                                                            property options

                                                                                                                                            options?: ICustomOptions;
                                                                                                                                            • Typegoose Custom Options

                                                                                                                                            property schemaOptions

                                                                                                                                            schemaOptions?: mongoose.SchemaOptions;
                                                                                                                                            • Supports all Mongoose's Schema Options

                                                                                                                                            interface INamingOptions

                                                                                                                                            interface INamingOptions {}
                                                                                                                                            • Interface for just all naming options

                                                                                                                                            property automaticName

                                                                                                                                            automaticName?: ICustomOptions['automaticName'];

                                                                                                                                            property customName

                                                                                                                                            customName?: ICustomOptions['customName'];

                                                                                                                                            property schemaCollection

                                                                                                                                            schemaCollection?: mongoose.SchemaOptions['collection'];

                                                                                                                                            interface InnerOuterOptions

                                                                                                                                            interface InnerOuterOptions {}

                                                                                                                                              property innerOptions

                                                                                                                                              innerOptions?: KeyStringAny;
                                                                                                                                              • Use this to define inner-options Use this if the auto-mapping is not correct or for plugin options

                                                                                                                                                Please open a new issue if some option is mismatched or not existing / mapped

                                                                                                                                              property outerOptions

                                                                                                                                              outerOptions?: KeyStringAny;
                                                                                                                                              • Use this to define outer-options Use this if the auto-mapping is not correct or for plugin options

                                                                                                                                                Please open a new issue if some option is mismatched or not existing / mapped

                                                                                                                                              interface IObjectWithTypegooseFunction

                                                                                                                                              interface IObjectWithTypegooseFunction {}
                                                                                                                                              • Interface describing a Object that has a "typegooseName" Function

                                                                                                                                              method typegooseName

                                                                                                                                              typegooseName: () => string;

                                                                                                                                                interface IPluginsArray

                                                                                                                                                interface IPluginsArray {}
                                                                                                                                                • Type for the Values stored in the Reflection for Plugins

                                                                                                                                                  Example 1

                                                                                                                                                  const plugins: IPluginsArray[] = Array.from(Reflect.getMetadata(DecoratorKeys.Plugins, target) ?? []);

                                                                                                                                                property mongoosePlugin

                                                                                                                                                mongoosePlugin: Func;
                                                                                                                                                • The Plugin Function to add

                                                                                                                                                property options

                                                                                                                                                options: any | undefined;
                                                                                                                                                • The Plugin's options, which could be anything because mongoose does not enforce it to be a object

                                                                                                                                                interface IPrototype

                                                                                                                                                interface IPrototype {}
                                                                                                                                                • For the types that error that seemingly don't have a prototype

                                                                                                                                                property prototype

                                                                                                                                                prototype?: any;

                                                                                                                                                  interface ITypegooseOptions

                                                                                                                                                  interface ITypegooseOptions {}

                                                                                                                                                    property disableGlobalCaching

                                                                                                                                                    disableGlobalCaching?: boolean;
                                                                                                                                                    • Option to disable caching globally completely disables the "constructors" and "models" maps "false" and "undefined" have the same result of enabling caching false

                                                                                                                                                    interface MapPropOptions

                                                                                                                                                    interface MapPropOptions extends BasePropOptions, InnerOuterOptions {}
                                                                                                                                                    • Options For Map's

                                                                                                                                                    interface ProcessPropOptions

                                                                                                                                                    interface ProcessPropOptions extends DecoratedPropertyMetadata {}
                                                                                                                                                    • Options used for "processProp"

                                                                                                                                                    property cl

                                                                                                                                                    cl: AnyParamConstructor<any>;
                                                                                                                                                    • The target Class's static version

                                                                                                                                                    interface TransformStringOptions

                                                                                                                                                    interface TransformStringOptions {}

                                                                                                                                                      property lowercase

                                                                                                                                                      lowercase?: mongoose.SchemaTypeOptions<any>['lowercase'];
                                                                                                                                                      • Should it be lowercased before save?

                                                                                                                                                      property trim

                                                                                                                                                      trim?: mongoose.SchemaTypeOptions<any>['trim'];
                                                                                                                                                      • Should it be trimmed before save?

                                                                                                                                                      property uppercase

                                                                                                                                                      uppercase?: mongoose.SchemaTypeOptions<any>['uppercase'];
                                                                                                                                                      • Should it be uppercased before save?

                                                                                                                                                      interface ValidateNumberOptions

                                                                                                                                                      interface ValidateNumberOptions {}

                                                                                                                                                        property enum

                                                                                                                                                        enum?: number[];
                                                                                                                                                        • Only allow Values from the enum

                                                                                                                                                        property max

                                                                                                                                                        max?: mongoose.SchemaTypeOptions<any>['max'];
                                                                                                                                                        • Only allow numbers lower than this

                                                                                                                                                        property min

                                                                                                                                                        min?: mongoose.SchemaTypeOptions<any>['min'];
                                                                                                                                                        • Only allow numbers that are higher than this

                                                                                                                                                        interface ValidateStringOptions

                                                                                                                                                        interface ValidateStringOptions {}

                                                                                                                                                          property enum

                                                                                                                                                          enum?: string[];
                                                                                                                                                          • Only allow Values from the enum

                                                                                                                                                          property match

                                                                                                                                                          match?: mongoose.SchemaTypeOptions<any>['match'];
                                                                                                                                                          • Only allow values that match this RegExp

                                                                                                                                                          property maxlength

                                                                                                                                                          maxlength?: mongoose.SchemaTypeOptions<any>['maxlength'];
                                                                                                                                                          • Only allow values that have at max this length

                                                                                                                                                          property minlength

                                                                                                                                                          minlength?: mongoose.SchemaTypeOptions<any>['minlength'];
                                                                                                                                                          • Only allow values that have at least this length

                                                                                                                                                          interface VirtualOptions

                                                                                                                                                          interface VirtualOptions {}

                                                                                                                                                            property count

                                                                                                                                                            count?: mongoose.VirtualTypeOptions['count'];
                                                                                                                                                            • Return the number of Documents found instead of the actual Documents

                                                                                                                                                            property foreignField

                                                                                                                                                            foreignField: mongoose.VirtualTypeOptions['foreignField'];
                                                                                                                                                            • Which property(on the ref-Class) to match localField against

                                                                                                                                                            property getters

                                                                                                                                                            getters?: mongoose.VirtualTypeOptions['getters'];
                                                                                                                                                            • If you set this to true, Mongoose will call any custom getters you defined on this virtual.

                                                                                                                                                              Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions

                                                                                                                                                            property justOne

                                                                                                                                                            justOne?: mongoose.VirtualTypeOptions['justOne'];
                                                                                                                                                            • Return as One Document(true) or as Array(false)

                                                                                                                                                            property limit

                                                                                                                                                            limit?: mongoose.VirtualTypeOptions['limit'];
                                                                                                                                                            • Add a default limit to the populate() query.

                                                                                                                                                              Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions

                                                                                                                                                            property localField

                                                                                                                                                            localField: mongoose.VirtualTypeOptions['localField'];
                                                                                                                                                            • Which property(on the current-Class) to match foreignField against

                                                                                                                                                            property match

                                                                                                                                                            match?: mongoose.VirtualTypeOptions['match'];
                                                                                                                                                            • Match Options

                                                                                                                                                            property options

                                                                                                                                                            options?: mongoose.VirtualTypeOptions['options'];
                                                                                                                                                            • Extra Query Options

                                                                                                                                                            property perDocumentLimit

                                                                                                                                                            perDocumentLimit?: mongoose.VirtualTypeOptions['perDocumentLimit'];
                                                                                                                                                            • For legacy reasons, limit with populate() may give incorrect results because it only executes a single query for every document being populated. If you set perDocumentLimit, Mongoose will ensure correct limit per document by executing a separate query for each document to populate(). For example, .find().populate({ path: 'test', perDocumentLimit: 2 }) will execute 2 additional queries if .find() returns 2 documents.

                                                                                                                                                              Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions

                                                                                                                                                            property ref

                                                                                                                                                            ref: NonNullable<BasePropOptions['ref']>;
                                                                                                                                                            • Reference another Document (Ref should be used as property type)

                                                                                                                                                            property skip

                                                                                                                                                            skip?: mongoose.VirtualTypeOptions['skip'];
                                                                                                                                                            • Add a default skip to the populate() query.

                                                                                                                                                              Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions

                                                                                                                                                            index signature

                                                                                                                                                            [extra: string]: any;

                                                                                                                                                              type AnyParamConstructor

                                                                                                                                                              type AnyParamConstructor<T> = new (...args: any) => T;
                                                                                                                                                              • Any-param Constructor

                                                                                                                                                              type ArraySubDocumentType

                                                                                                                                                              type ArraySubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<
                                                                                                                                                              T,
                                                                                                                                                              QueryHelpers
                                                                                                                                                              > &
                                                                                                                                                              mongoose.Types.ArraySubdocument;
                                                                                                                                                              • Get the Type of an instance of a SubDocument that exists within an array, with Class properties

                                                                                                                                                              type AsQueryMethod

                                                                                                                                                              type AsQueryMethod<T extends (...args: any) => any> = (
                                                                                                                                                              ...args: Parameters<T>
                                                                                                                                                              ) => ReturnType<T>;
                                                                                                                                                              • Gets the signature (parameters with their types, and the return type) of a function type.

                                                                                                                                                                Should be used when defining an interface for a class that uses query methods.

                                                                                                                                                                Example 1

                                                                                                                                                                function sendMessage(recipient: string, sender: string, priority: number, retryIfFails: boolean) {
                                                                                                                                                                // some logic...
                                                                                                                                                                return true;
                                                                                                                                                                }
                                                                                                                                                                // Both of the following types will be identical.
                                                                                                                                                                type SendMessageType = AsQueryMethod<typeof sendMessage>;
                                                                                                                                                                type SendMessageManualType = (recipient: string, sender: string, priority: number, retryIfFails: boolean) => boolean;

                                                                                                                                                              type BeAnObject

                                                                                                                                                              type BeAnObject = Record<string, any>;
                                                                                                                                                              • This type is for lint error "ban-types" where "{}" would be used This type is separate from "KeyStringAny" because it has a different meaning

                                                                                                                                                              type BeAnyObject

                                                                                                                                                              type BeAnyObject = {};
                                                                                                                                                              • This type is for mongoose-specific things where BeAnObject does not work see https://github.com/Automattic/mongoose/issues/13094

                                                                                                                                                              type CustomNameFunction

                                                                                                                                                              type CustomNameFunction = (options: IModelOptions) => string;
                                                                                                                                                              • The Type of a function to generate a custom model name.

                                                                                                                                                              type DecoratedPropertyMetadataMap

                                                                                                                                                              type DecoratedPropertyMetadataMap = Map<string | symbol, DecoratedPropertyMetadata>;

                                                                                                                                                                type DeferredFunc

                                                                                                                                                                type DeferredFunc<T = any> = (...args: unknown[]) => T;
                                                                                                                                                                • Defer a reference with a function (or as other projects call it "Forward declaration")

                                                                                                                                                                  Parameter type

                                                                                                                                                                  This is just to comply with the common pattern of type => ActualType

                                                                                                                                                                type DocumentType

                                                                                                                                                                type DocumentType<T, QueryHelpers = BeAnObject> = mongoose.Document<
                                                                                                                                                                unknown,
                                                                                                                                                                QueryHelpers,
                                                                                                                                                                T
                                                                                                                                                                > &
                                                                                                                                                                mongoose.Require_id<T> &
                                                                                                                                                                IObjectWithTypegooseFunction;
                                                                                                                                                                • Get the Type of an instance of a Document with Class properties

                                                                                                                                                                  Example 1

                                                                                                                                                                  class ClassName {
                                                                                                                                                                  @prop()
                                                                                                                                                                  public someProperty: string;
                                                                                                                                                                  }
                                                                                                                                                                  const NameModel = getModelForClass(ClassName);
                                                                                                                                                                  const doc: DocumentType<ClassName> = await NameModel.create({});

                                                                                                                                                                type DynamicStringFunc

                                                                                                                                                                type DynamicStringFunc<T extends AnyParamConstructor<any>> = (
                                                                                                                                                                doc: DocumentType<T>
                                                                                                                                                                ) => string;
                                                                                                                                                                • Dynamic Functions, since mongoose 4.13

                                                                                                                                                                  Parameter doc

                                                                                                                                                                  The Document current document

                                                                                                                                                                type EnumCombinedType

                                                                                                                                                                type EnumCombinedType = EnumValues | EnumObj;

                                                                                                                                                                type EnumValues

                                                                                                                                                                type EnumValues =
                                                                                                                                                                | Array<string | number | null>
                                                                                                                                                                | ReadonlyArray<string | number | null>
                                                                                                                                                                | {
                                                                                                                                                                [path: string | number]: string | number | null;
                                                                                                                                                                };
                                                                                                                                                                • Type for enum "values"

                                                                                                                                                                type FilterOutFunctionKeys

                                                                                                                                                                type FilterOutFunctionKeys<T extends object> = Omit<T, GetFunctionKeys<T>>;
                                                                                                                                                                • Remove all properties from "T" that are a function does NOT filter out getters / setters

                                                                                                                                                                type Func

                                                                                                                                                                type Func = (...args: any[]) => any;
                                                                                                                                                                • Generic "Function" type, because typescript does not like using "Function" directly in strict mode

                                                                                                                                                                type GetFunctionKeys

                                                                                                                                                                type GetFunctionKeys<T extends object> = {
                                                                                                                                                                [K in keyof T]: T[K] extends (...args: any) => any ? K : never;
                                                                                                                                                                }[keyof T];
                                                                                                                                                                • Get all keys from "T" that are a function does NOT filter out getters / setters

                                                                                                                                                                type HookOptionsEither

                                                                                                                                                                type HookOptionsEither = mongoose.SchemaPreOptions | mongoose.SchemaPostOptions;
                                                                                                                                                                • A Helper type to combine both mongoose Hook Option types

                                                                                                                                                                type IndexOptions

                                                                                                                                                                type IndexOptions = mongoose.IndexOptions;
                                                                                                                                                                • Alias of "mongoose.IndexOptions" for convenience

                                                                                                                                                                type KeyStringAny

                                                                                                                                                                type KeyStringAny = Record<string, any>;
                                                                                                                                                                • A Helper Interface for defining a "key" index of "string" and "value" of "any"

                                                                                                                                                                type ModelType

                                                                                                                                                                type ModelType<T, QueryHelpers = BeAnObject> = mongoose.Model<
                                                                                                                                                                T, // raw doc type
                                                                                                                                                                QueryHelpers, // query helpers
                                                                                                                                                                IObjectWithTypegooseFunction, // instance methods
                                                                                                                                                                BeAnyObject
                                                                                                                                                                >;
                                                                                                                                                                • Used Internally for ModelTypes

                                                                                                                                                                type NestedDiscriminatorsFunction

                                                                                                                                                                type NestedDiscriminatorsFunction = DeferredFunc<
                                                                                                                                                                (AnyParamConstructor<any> | DiscriminatorObject)[]
                                                                                                                                                                >;
                                                                                                                                                                • Type to keep the "discriminators" options consistent in types

                                                                                                                                                                type NestedDiscriminatorsMap

                                                                                                                                                                type NestedDiscriminatorsMap = Map<string, DiscriminatorObject[]>;
                                                                                                                                                                • Type for the Values stored in the Reflection for Nested Discriminators

                                                                                                                                                                  Example 1

                                                                                                                                                                  const disMap: NestedDiscriminatorsMap = new Map(Reflect.getMetadata(DecoratorKeys.NestedDiscriminators, target) ?? []);

                                                                                                                                                                type PropOptionsForNumber

                                                                                                                                                                type PropOptionsForNumber = BasePropOptions & ValidateNumberOptions;

                                                                                                                                                                  type PropOptionsForString

                                                                                                                                                                  type PropOptionsForString = BasePropOptions &
                                                                                                                                                                  TransformStringOptions &
                                                                                                                                                                  ValidateStringOptions;

                                                                                                                                                                    type QueryHelperThis

                                                                                                                                                                    type QueryHelperThis<
                                                                                                                                                                    T extends AnyParamConstructor<any>,
                                                                                                                                                                    QueryHelpers,
                                                                                                                                                                    S = DocumentType<InstanceType<T>, QueryHelpers>
                                                                                                                                                                    > = mongoose.QueryWithHelpers<S | null, S, QueryHelpers, InstanceType<T>>;
                                                                                                                                                                    • Helper type to easily set the this type in a QueryHelper function

                                                                                                                                                                      Example 1

                                                                                                                                                                      function findById(this: QueryHelperThis<typeof YourClass, YourClassQueryHelpers>, id: string) { return this.findOne({ _id: id }); }

                                                                                                                                                                    type QueryMethodMap

                                                                                                                                                                    type QueryMethodMap = Map<string, Func>;
                                                                                                                                                                    • Type for the Values stored in the Reflection for Query Methods

                                                                                                                                                                      Example 1

                                                                                                                                                                      const queryMethods: QueryMethodMap = new Map(Reflect.getMetadata(DecoratorKeys.QueryMethod, target) ?? []);

                                                                                                                                                                    type Ref

                                                                                                                                                                    type Ref<
                                                                                                                                                                    PopulatedType,
                                                                                                                                                                    RawId extends mongoose.RefType = PopulatedType extends {
                                                                                                                                                                    _id?: mongoose.RefType;
                                                                                                                                                                    }
                                                                                                                                                                    ? NonNullable<PopulatedType['_id']>
                                                                                                                                                                    : mongoose.Types.ObjectId
                                                                                                                                                                    > = mongoose.PopulatedDoc<DocumentType<PopulatedType>, RawId>;
                                                                                                                                                                    • Reference another Model

                                                                                                                                                                    type RefType

                                                                                                                                                                    type RefType = mongoose.RefType;

                                                                                                                                                                      type ReturnModelType

                                                                                                                                                                      type ReturnModelType<
                                                                                                                                                                      U extends AnyParamConstructor<any>,
                                                                                                                                                                      QueryHelpers = BeAnObject
                                                                                                                                                                      > = ModelType<InstanceType<U>, QueryHelpers> & U;
                                                                                                                                                                      • The Type for Models used in typegoose, mostly returned by "getModelForClass" and "addModelToTypegoose"

                                                                                                                                                                        Example 1

                                                                                                                                                                        const Model: ReturnModelType<typeof YourClass, YourClassQueryHelper> = mongoose.model("YourClass", YourClassSchema);

                                                                                                                                                                      type SearchIndexDescription

                                                                                                                                                                      type SearchIndexDescription = mongoose.SearchIndexDescription;
                                                                                                                                                                      • Type for the Values stored in the Reflection for Search Indexes

                                                                                                                                                                        Example 1

                                                                                                                                                                        const searchIndices: SearchIndexDescription[] = Reflect.getMetadata(DecoratorKeys.SearchIndex, target) || [];

                                                                                                                                                                      type SubDocumentType

                                                                                                                                                                      type SubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<T, QueryHelpers> &
                                                                                                                                                                      mongoose.Types.Subdocument;
                                                                                                                                                                      • Get the Type of an instance of a SubDocument with Class properties

                                                                                                                                                                      type VirtualPopulateMap

                                                                                                                                                                      type VirtualPopulateMap = Map<string, VirtualOptions & Record<string, unknown>>;
                                                                                                                                                                      • Type for the Values stored in the Reflection for Virtual Populates

                                                                                                                                                                        Example 1

                                                                                                                                                                        const virtuals: VirtualPopulateMap = new Map(Reflect.getMetadata(DecoratorKeys.VirtualPopulate, target.constructor) ?? []);

                                                                                                                                                                      Package Files (16)

                                                                                                                                                                      Dependencies (5)

                                                                                                                                                                      Dev Dependencies (26)

                                                                                                                                                                      Peer Dependencies (1)

                                                                                                                                                                      Badge

                                                                                                                                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@typegoose/typegoose.

                                                                                                                                                                      • Markdown
                                                                                                                                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@typegoose/typegoose)
                                                                                                                                                                      • HTML
                                                                                                                                                                        <a href="https://www.jsdocs.io/package/@typegoose/typegoose"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>