User interface

interface IUser {
    _id: unknown;
    $locals: Record<string, unknown>;
    $op:
        | null
        | "remove"
        | "validate"
        | "save";
    $where: Record<string, unknown>;
    baseModelName?: string;
    collection: Collection<Document>;
    db: Connection;
    email: string;
    errors?: ValidationError;
    id?: any;
    isNew: boolean;
    password: string;
    schema: Schema<any, Model<any, any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, {}, Document<unknown, {}, FlatRecord<{}>> & FlatRecord<{}> & Required<{
        _id: unknown;
    }> & {
        __v: number;
    }>;
    $assertPopulated<Paths>(path: string | string[], values?: Partial<Paths>): Omit<IUser, keyof Paths> & Paths;
    $clearModifiedPaths(): this;
    $clone(): this;
    $createModifiedPathsSnapshot(): ModifiedPathsSnapshot;
    $getAllSubdocs(): Document<unknown, any, any>[];
    $getPopulatedDocs(): Document<unknown, any, any>[];
    $ignore(path: string): void;
    $inc(path: string | string[], val?: number): this;
    $isDefault(path: string): boolean;
    $isDeleted(val?: boolean): boolean;
    $isEmpty(path: string): boolean;
    $isValid(path: string): boolean;
    $markValid(path: string): void;
    $model<ModelType>(name: string): ModelType;
    $model<ModelType>(): ModelType;
    $parent(): undefined | Document<unknown, any, any>;
    $restoreModifiedPathsSnapshot(snapshot: ModifiedPathsSnapshot): this;
    $session(session?: null | ClientSession): null | ClientSession;
    $set(path: string | Record<string, any>, val: any, type: any, options?: DocumentSetOptions): this;
    $set(path: string | Record<string, any>, val: any, options?: DocumentSetOptions): this;
    $set(value: string | Record<string, any>): this;
    deleteOne(options?: QueryOptions<unknown>): any;
    depopulate<Paths>(path?: string | string[]): MergeType<IUser, Paths>;
    directModifiedPaths(): string[];
    equals(doc: Document<unknown, any, any>): boolean;
    get<T>(path: T, type?: any, options?: any): any;
    get(path: string, type?: any, options?: any): any;
    getChanges(): UpdateQuery<IUser>;
    increment(): this;
    init(obj: AnyObject, opts?: AnyObject): this;
    invalidate<T>(path: T, errorMsg: string | NativeError, value?: any, kind?: string): null | NativeError;
    invalidate(path: string, errorMsg: string | NativeError, value?: any, kind?: string): null | NativeError;
    isDirectModified<T>(path: T | T[]): boolean;
    isDirectModified(path: string | string[]): boolean;
    isDirectSelected<T>(path: T): boolean;
    isDirectSelected(path: string): boolean;
    isInit<T>(path: T): boolean;
    isInit(path: string): boolean;
    isModified<T>(path?: T | T[], options?: null | {
        ignoreAtomics?: boolean;
    }): boolean;
    isModified(path?: string | string[], options?: null | {
        ignoreAtomics?: boolean;
    }): boolean;
    isSelected<T>(path: T): boolean;
    isSelected(path: string): boolean;
    markModified<T>(path: T, scope?: any): void;
    markModified(path: string, scope?: any): void;
    matchPassword(enteredPassword: string): Promise<boolean>;
    model<ModelType>(name: string): ModelType;
    model<ModelType>(): ModelType;
    modifiedPaths(options?: {
        includeChildren?: boolean;
    }): string[];
    overwrite(obj: AnyObject): this;
    populate<Paths>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<IUser, Paths>>;
    populate<Paths>(path: string, select?: string | AnyObject, model?: Model<any, {}, {}, {}, any, any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<IUser, Paths>>;
    populated(path: string): any;
    replaceOne(replacement?: AnyObject, options?: null | QueryOptions<unknown>): Query<any, IUser, {}, unknown, "find", Record<string, never>>;
    save(options?: SaveOptions): Promise<IUser>;
    set<T>(path: T, val: any, type: any, options?: DocumentSetOptions): this;
    set(path: string | Record<string, any>, val: any, type: any, options?: DocumentSetOptions): this;
    set(path: string | Record<string, any>, val: any, options?: DocumentSetOptions): this;
    set(value: string | Record<string, any>): this;
    toJSON(options?: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps?: true;
        flattenObjectIds?: false;
    }): FlattenMaps<any>;
    toJSON(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenObjectIds: false;
    }): FlattenMaps<any>;
    toJSON(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenObjectIds: true;
    }): {};
    toJSON(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps: false;
    }): any;
    toJSON(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps: false;
        flattenObjectIds: true;
    }): any;
    toJSON<T>(options?: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps?: true;
        flattenObjectIds?: false;
    }): FlattenMaps<T>;
    toJSON<T>(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenObjectIds: false;
    }): FlattenMaps<T>;
    toJSON<T>(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenObjectIds: true;
    }): ObjectIdToString<FlattenMaps<T>>;
    toJSON<T>(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps: false;
    }): T;
    toJSON<T>(options: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }> & {
        flattenMaps: false;
        flattenObjectIds: true;
    }): ObjectIdToString<T>;
    toObject(options?: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }>): any;
    toObject<T>(options?: ToObjectOptions<Document<unknown, {}, unknown> & {
        _id: ObjectId;
    } & {
        __v: number;
    }>): Require_id<T>;
    unmarkModified<T>(path: T): void;
    unmarkModified(path: string): void;
    updateOne(update?: UpdateWithAggregationPipeline | UpdateQuery<IUser>, options?: null | QueryOptions<unknown>): Query<any, IUser, {}, unknown, "find", Record<string, never>>;
    validate<T>(pathsToValidate?: T | T[], options?: AnyObject): Promise<void>;
    validate(pathsToValidate?: PathsToValidate, options?: AnyObject): Promise<void>;
    validate(options: {
        pathsToSkip?: pathsToSkip;
    }): Promise<void>;
    validateSync(options: {
        pathsToSkip?: pathsToSkip;
        [k: string]: any;
    }): null | ValidationError;
    validateSync<T>(pathsToValidate?: T | T[], options?: AnyObject): null | ValidationError;
    validateSync(pathsToValidate?: PathsToValidate, options?: AnyObject): null | ValidationError;
}

Hierarchy

  • Document
    • IUser

Properties

_id: unknown

This documents _id.

$locals: Record<string, unknown>

Empty object that you can use for storing properties on the document. This is handy for passing data to middleware without conflicting with Mongoose internals.

$op:
    | null
    | "remove"
    | "validate"
    | "save"

A string containing the current operation that Mongoose is executing on this document. Can be null, 'save', 'validate', or 'remove'.

$where: Record<string, unknown>

Set this property to add additional query filters when Mongoose saves this document and isNew is false.

baseModelName?: string

If this is a discriminator model, baseModelName is the name of the base model.

collection: Collection<Document>

Collection the model uses.

db: Connection

Connection the model uses.

email: string

The user email.

errors?: ValidationError

Returns the current validation errors.

id?: any

The string version of this documents _id.

isNew: boolean

Boolean flag specifying if the document is new.

password: string

The user password.

schema: Schema<any, Model<any, any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, {}, Document<unknown, {}, FlatRecord<{}>> & FlatRecord<{}> & Required<{
    _id: unknown;
}> & {
    __v: number;
}>

The document's schema.

Methods

  • Assert that a given path or paths is populated. Throws an error if not populated.

    Type Parameters

    • Paths = {}

    Parameters

    • path: string | string[]
    • Optionalvalues: Partial<Paths>

    Returns Omit<IUser, keyof Paths> & Paths

  • Clear the document's modified paths.

    Returns this

  • Returns a deep clone of this document

    Returns this

  • Creates a snapshot of this document's internal change tracking state. You can later reset this document's change tracking state using $restoreModifiedPathsSnapshot().

    Returns ModifiedPathsSnapshot

  • Returns Document<unknown, any, any>[]

  • Returns an array of all populated documents associated with the query

    Returns Document<unknown, any, any>[]

  • Don't run validation on this path or persist changes to this path.

    Parameters

    • path: string

    Returns void

  • Increments the numeric value at path by the given val. When you call save() on this document, Mongoose will send a $inc as opposed to a $set.

    Parameters

    • path: string | string[]
    • Optionalval: number

    Returns this

  • Checks if a path is set to its default.

    Parameters

    • path: string

    Returns boolean

  • Getter/setter, determines whether the document was removed or not.

    Parameters

    • Optionalval: boolean

    Returns boolean

  • Returns true if the given path is nullish or only contains empty objects. Useful for determining whether this subdoc will get stripped out by the minimize option.

    Parameters

    • path: string

    Returns boolean

  • Checks if a path is invalid

    Parameters

    • path: string

    Returns boolean

  • Marks a path as valid, removing existing validation errors.

    Parameters

    • path: string

    Returns void

  • Returns the model with the given name on this document's associated connection.

    Type Parameters

    • ModelType = Model<unknown, {}, {}, {}, Document<unknown, {}, unknown> & {
          _id: ObjectId;
      } & {
          __v: number;
      }, any>

    Parameters

    • name: string

    Returns ModelType

  • Type Parameters

    • ModelType = Model<any, {}, {}, {}, any, any>

    Returns ModelType

  • If this document is a subdocument or populated document, returns the document's parent. Returns undefined otherwise.

    Returns undefined | Document<unknown, any, any>

  • Restore this document's change tracking state to the given snapshot. Note that $restoreModifiedPathsSnapshot() does not modify the document's properties, just resets the change tracking state.

    Parameters

    • snapshot: ModifiedPathsSnapshot

    Returns this

  • Getter/setter around the session associated with this document. Used to automatically set session if you save() a doc that you got from a query with an associated session.

    Parameters

    • Optionalsession: null | ClientSession

    Returns null | ClientSession

  • Alias for set(), used internally to avoid conflicts

    Parameters

    • path: string | Record<string, any>
    • val: any
    • type: any
    • Optionaloptions: DocumentSetOptions

    Returns this

  • Parameters

    • path: string | Record<string, any>
    • val: any
    • Optionaloptions: DocumentSetOptions

    Returns this

  • Parameters

    • value: string | Record<string, any>

    Returns this

  • Removes this document from the db.

    Parameters

    • Optionaloptions: QueryOptions<unknown>

    Returns any

  • Takes a populated field and returns it to its unpopulated state. If called with no arguments, then all populated fields are returned to their unpopulated state.

    Type Parameters

    • Paths = {}

    Parameters

    • Optionalpath: string | string[]

    Returns MergeType<IUser, Paths>

  • Returns the list of paths that have been directly modified. A direct modified path is a path that you explicitly set, whether via doc.foo = 'bar', Object.assign(doc, { foo: 'bar' }), or doc.set('foo', 'bar').

    Returns string[]

  • Returns true if this document is equal to another document.

    Documents are considered equal when they have matching _ids, unless neither document has an _id, in which case this function falls back to using deepEqual().

    Parameters

    • doc: Document<unknown, any, any>

    Returns boolean

  • Returns the value of a path.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T
    • Optionaltype: any
    • Optionaloptions: any

    Returns any

  • Parameters

    • path: string
    • Optionaltype: any
    • Optionaloptions: any

    Returns any

  • Returns the changes that happened to the document in the format that will be sent to MongoDB.

    Returns UpdateQuery<IUser>

  • Signal that we desire an increment of this documents version.

    Returns this

  • Initializes the document without setters or marking anything modified. Called internally after a document is returned from mongodb. Normally, you do not need to call this function on your own.

    Parameters

    • obj: AnyObject
    • Optionalopts: AnyObject

    Returns this

  • Marks a path as invalid, causing validation to fail.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T
    • errorMsg: string | NativeError
    • Optionalvalue: any
    • Optionalkind: string

    Returns null | NativeError

  • Parameters

    • path: string
    • errorMsg: string | NativeError
    • Optionalvalue: any
    • Optionalkind: string

    Returns null | NativeError

  • Returns true if path was directly set and modified, else false.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T | T[]

    Returns boolean

  • Parameters

    • path: string | string[]

    Returns boolean

  • Checks if path was explicitly selected. If no projection, always returns true.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T

    Returns boolean

  • Parameters

    • path: string

    Returns boolean

  • Checks if path is in the init state, that is, it was set by Document#init() and not modified since.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T

    Returns boolean

  • Parameters

    • path: string

    Returns boolean

  • Returns true if any of the given paths are modified, else false. If no arguments, returns true if any path in this document is modified.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • Optionalpath: T | T[]
    • Optionaloptions: null | {
          ignoreAtomics?: boolean;
      }

    Returns boolean

  • Parameters

    • Optionalpath: string | string[]
    • Optionaloptions: null | {
          ignoreAtomics?: boolean;
      }

    Returns boolean

  • Checks if path was selected in the source query which initialized this document.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T

    Returns boolean

  • Parameters

    • path: string

    Returns boolean

  • Marks the path as having pending changes to write to the db.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T
    • Optionalscope: any

    Returns void

  • Parameters

    • path: string
    • Optionalscope: any

    Returns void

  • Match the entered password with the user password.

    Parameters

    • enteredPassword: string

      The entered password.

    Returns Promise<boolean>

    A promise that resolves to a boolean indicating if the passwords match.

  • Returns the model with the given name on this document's associated connection.

    Type Parameters

    • ModelType = Model<unknown, {}, {}, {}, Document<unknown, {}, unknown> & {
          _id: ObjectId;
      } & {
          __v: number;
      }, any>

    Parameters

    • name: string

    Returns ModelType

  • Type Parameters

    • ModelType = Model<any, {}, {}, {}, any, any>

    Returns ModelType

  • Returns the list of paths that have been modified.

    Parameters

    • Optionaloptions: {
          includeChildren?: boolean;
      }
      • OptionalincludeChildren?: boolean

    Returns string[]

  • Overwrite all values in this document with the values of obj, except for immutable properties. Behaves similarly to set(), except for it unsets all properties that aren't in obj.

    Parameters

    • obj: AnyObject

    Returns this

  • Populates document references.

    Type Parameters

    • Paths = {}

    Parameters

    • path: string | PopulateOptions | (string | PopulateOptions)[]

    Returns Promise<MergeType<IUser, Paths>>

  • Type Parameters

    • Paths = {}

    Parameters

    • path: string
    • Optionalselect: string | AnyObject
    • Optionalmodel: Model<any, {}, {}, {}, any, any>
    • Optionalmatch: AnyObject
    • Optionaloptions: PopulateOptions

    Returns Promise<MergeType<IUser, Paths>>

  • Gets _id(s) used during population of the given path. If the path was not populated, returns undefined.

    Parameters

    • path: string

    Returns any

  • Sends a replaceOne command with this document _id as the query selector.

    Parameters

    • Optionalreplacement: AnyObject
    • Optionaloptions: null | QueryOptions<unknown>

    Returns Query<any, IUser, {}, unknown, "find", Record<string, never>>

  • Saves this document by inserting a new document into the database if document.isNew is true, or sends an updateOne operation with just the modified paths if isNew is false.

    Parameters

    • Optionaloptions: SaveOptions

    Returns Promise<IUser>

  • Sets the value of a path, or many paths.

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • path: T
    • val: any
    • type: any
    • Optionaloptions: DocumentSetOptions

    Returns this

  • Parameters

    • path: string | Record<string, any>
    • val: any
    • type: any
    • Optionaloptions: DocumentSetOptions

    Returns this

  • Parameters

    • path: string | Record<string, any>
    • val: any
    • Optionaloptions: DocumentSetOptions

    Returns this

  • Parameters

    • value: string | Record<string, any>

    Returns this

  • The return value of this method is used in calls to JSON.stringify(doc).

    Parameters

    • Optionaloptions: ToObjectOptions<Document<unknown, {}, unknown> & {
          _id: ObjectId;
      } & {
          __v: number;
      }> & {
          flattenMaps?: true;
          flattenObjectIds?: false;
      }

    Returns FlattenMaps<any>

  • Parameters

    • options: ToObjectOptions<Document<unknown, {}, unknown> & {
          _id: ObjectId;
      } & {
          __v: number;
      }> & {
          flattenObjectIds: false;
      }

    Returns FlattenMaps<any>

  • Parameters

    • options: ToObjectOptions<Document<unknown, {}, unknown> & {
          _id: ObjectId;
      } & {
          __v: number;
      }> & {
          flattenObjectIds: true;
      }

    Returns {}

    • Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenMaps: false;
        }

      Returns any

    • Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenMaps: false;
            flattenObjectIds: true;
        }

      Returns any

    • Type Parameters

      • T = any

      Parameters

      • Optionaloptions: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenMaps?: true;
            flattenObjectIds?: false;
        }

      Returns FlattenMaps<T>

    • Type Parameters

      • T = any

      Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenObjectIds: false;
        }

      Returns FlattenMaps<T>

    • Type Parameters

      • T = any

      Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenObjectIds: true;
        }

      Returns ObjectIdToString<FlattenMaps<T>>

    • Type Parameters

      • T = any

      Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenMaps: false;
        }

      Returns T

    • Type Parameters

      • T = any

      Parameters

      • options: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }> & {
            flattenMaps: false;
            flattenObjectIds: true;
        }

      Returns ObjectIdToString<T>

    • Converts this document into a plain-old JavaScript object (POJO).

      Parameters

      • Optionaloptions: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }>

      Returns any

    • Type Parameters

      • T

      Parameters

      • Optionaloptions: ToObjectOptions<Document<unknown, {}, unknown> & {
            _id: ObjectId;
        } & {
            __v: number;
        }>

      Returns Require_id<T>

    • Clears the modified state on the specified path.

      Type Parameters

      • T extends string | number | symbol

      Parameters

      • path: T

      Returns void

    • Parameters

      • path: string

      Returns void

    • Sends an updateOne command with this document _id as the query selector.

      Parameters

      • Optionalupdate: UpdateWithAggregationPipeline | UpdateQuery<IUser>
      • Optionaloptions: null | QueryOptions<unknown>

      Returns Query<any, IUser, {}, unknown, "find", Record<string, never>>

    • Executes registered validation rules for this document.

      Type Parameters

      • T extends string | number | symbol

      Parameters

      • OptionalpathsToValidate: T | T[]
      • Optionaloptions: AnyObject

      Returns Promise<void>

    • Parameters

      • OptionalpathsToValidate: PathsToValidate
      • Optionaloptions: AnyObject

      Returns Promise<void>

    • Parameters

      • options: {
            pathsToSkip?: pathsToSkip;
        }
        • OptionalpathsToSkip?: pathsToSkip

      Returns Promise<void>

    • Executes registered validation rules (skipping asynchronous validators) for this document.

      Parameters

      • options: {
            pathsToSkip?: pathsToSkip;
            [k: string]: any;
        }
        • [k: string]: any
        • OptionalpathsToSkip?: pathsToSkip

      Returns null | ValidationError

    • Type Parameters

      • T extends string | number | symbol

      Parameters

      • OptionalpathsToValidate: T | T[]
      • Optionaloptions: AnyObject

      Returns null | ValidationError

    • Parameters

      • OptionalpathsToValidate: PathsToValidate
      • Optionaloptions: AnyObject

      Returns null | ValidationError