Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IUser

Hierarchy

Index

Constructors

constructor

  • Parameters

    • Optional doc: any

    Returns IUserSchema

Properties

base

base: __module

Base Mongoose instance the model uses.

baseModelName

baseModelName: string

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

collection

collection: Collection

Collection the model uses.

db

db: Connection

Connection the model uses.

discriminators

discriminators: {}

Registered discriminators for this model.

Type declaration

  • [name: string]: Model<any>

events

events: EventEmitter

Event emitter that reports any errors that occurred. Useful for global error handling.

modelName

modelName: string

The name of the model

schema

schema: Schema<Document<any, {}>, Model<any, any>, undefined>

Schema the model uses.

Methods

$where

  • Adds a $where clause to this query

    Parameters

    • argument: string | Function

    Returns Query<IUserSchema[], IUserSchema, {}>

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

aggregate

  • aggregate<R>(pipeline?: any[]): Aggregate<R[]>
  • aggregate<R>(pipeline: any[], cb: Function): Promise<R[]>
  • Type parameters

    • R = any

    Parameters

    • Optional pipeline: any[]

    Returns Aggregate<R[]>

  • Type parameters

    • R = any

    Parameters

    • pipeline: any[]
    • cb: Function

    Returns Promise<R[]>

authenticate

  • authenticate(email: string, password: string, params?: object): Promise<false | IUserSchema>
  • Check for user credentials, generate its token and return information

    Parameters

    • email: string

      Email credentials

    • password: string

      Password credentials

    • Optional params: object

      Parameters to given to the token creation (default: undefined)

    Returns Promise<false | IUserSchema>

    The user instance if a user matches the credentials, false otherwise

    const email = '...'
    const password = '...'
    const user = await User.authenticate(email, password, { ...tokenParams })
    
    if(user) {
            console.log('Connection successful !')
    }
    

bulkWrite

  • bulkWrite(writes: any[], options?: CollectionBulkWriteOptions): Promise<BulkWriteOpResultObject>
  • bulkWrite(writes: any[], options?: CollectionBulkWriteOptions, cb?: (err: any, res: BulkWriteOpResultObject) => void): void
  • Sends multiple insertOne, updateOne, updateMany, replaceOne, deleteOne, and/or deleteMany operations to the MongoDB server in one command. This is faster than sending multiple independent operations (e.g. if you use create()) because with bulkWrite() there is only one round trip to MongoDB.

    Parameters

    • writes: any[]
    • Optional options: CollectionBulkWriteOptions

    Returns Promise<BulkWriteOpResultObject>

  • Parameters

    • writes: any[]
    • Optional options: CollectionBulkWriteOptions
    • Optional cb: (err: any, res: BulkWriteOpResultObject) => void
        • (err: any, res: BulkWriteOpResultObject): void
        • Parameters

          • err: any
          • res: BulkWriteOpResultObject

          Returns void

    Returns void

checkPassword

  • checkPassword(password: string, hash: string): Promise<boolean>
  • Check if a hashed password correspond to a plain text password

    Parameters

    • password: string

      Password to compare to the hash

    • hash: string

      Hash to compare to the password

    Returns Promise<boolean>

    True if the password and the hash match, false otherwise

    await User.checkPassword('password', '$2b$10$ZcXGphJNeWfjc6F0klucDe1SRvh6XOLbgAop/RoBg.U3eXEGnP6xm')
    // -> true
    
    await User.checkPassword('passw0rd', '$2b$10$ZcXGphJNeWfjc6F0klucDe1SRvh6XOLbgAop/RoBg.U3eXEGnP6xm')
    // -> false
    

count

  • count(callback?: (err: any, count: number) => void): Query<number, IUserSchema, {}>
  • count(filter: FilterQuery<IUserSchema>, callback?: (err: any, count: number) => void): Query<number, IUserSchema, {}>
  • Creates a count query: counts the number of documents that match filter.

    Parameters

    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<number, IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<number, IUserSchema, {}>

countDocuments

  • countDocuments(callback?: (err: any, count: number) => void): Query<number, IUserSchema, {}>
  • countDocuments(filter: FilterQuery<IUserSchema>, callback?: (err: any, count: number) => void): Query<number, IUserSchema, {}>
  • Creates a countDocuments query: counts the number of documents that match filter.

    Parameters

    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<number, IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<number, IUserSchema, {}>

create

  • Creates a new document or documents

    Parameters

    Returns Promise<IUserSchema>

  • Parameters

    Returns Promise<IUserSchema[]>

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Type parameters

    Parameters

    • docs: DocContents[]
    • Optional options: SaveOptions

    Returns Promise<IUserSchema[]>

  • Type parameters

    Parameters

    • doc: DocContents

    Returns Promise<IUserSchema>

  • Type parameters

    Parameters

    • Rest ...docs: DocContents[]

    Returns Promise<IUserSchema[]>

  • Type parameters

    Parameters

    • docs: DocContents[]
    • callback: (err: NativeError, docs: IUserSchema[]) => void

    Returns void

  • Type parameters

    Parameters

    • doc: DocContents
    • callback: (err: NativeError, doc: IUserSchema) => void

    Returns void

createCollection

  • createCollection(options?: CollectionCreateOptions): Promise<Collection<IUserSchema>>
  • createCollection(options: CollectionCreateOptions, callback: (err: NativeError, collection: Collection<IUserSchema>) => void): void
  • Create the collection for this model. By default, if no indexes are specified, mongoose will not create the collection for the model until any documents are created. Use this method to create the collection explicitly.

    Parameters

    • Optional options: CollectionCreateOptions

    Returns Promise<Collection<IUserSchema>>

  • Parameters

    • options: CollectionCreateOptions
    • callback: (err: NativeError, collection: Collection<IUserSchema>) => void
        • (err: NativeError, collection: Collection<IUserSchema>): void
        • Parameters

          Returns void

    Returns void

createIndexes

  • createIndexes(callback?: (err: any) => void): Promise<void>
  • createIndexes(options?: any, callback?: (err: any) => void): Promise<void>
  • Similar to ensureIndexes(), except for it uses the createIndex function.

    Parameters

    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

  • Parameters

    • Optional options: any
    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

deleteMany

  • deleteMany(filter?: FilterQuery<IUserSchema>, options?: QueryOptions, callback?: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • deleteMany(filter: FilterQuery<IUserSchema>, callback: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • deleteMany(callback: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • Deletes all of the documents that match conditions from the collection. Behaves like remove(), but deletes all documents that match conditions regardless of the single option.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

  • Parameters

    • callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

deleteOne

  • deleteOne(filter?: FilterQuery<IUserSchema>, options?: QueryOptions, callback?: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • deleteOne(filter: FilterQuery<IUserSchema>, callback: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • deleteOne(callback: (err: NativeError) => void): Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>
  • Deletes the first document that matches conditions from the collection. Behaves like remove(), but deletes at most one document regardless of the single option.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

  • Parameters

    • callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<{ n?: number; ok?: number } & { deletedCount?: number }, IUserSchema, {}>

discriminator

  • discriminator<D>(name: string | number, schema: Schema<D, Model<any, any>, undefined>, value?: string): Model<D, {}>
  • discriminator<T, U>(name: string | number, schema: Schema<T, U, undefined>, value?: string): U
  • Adds a discriminator type.

    Type parameters

    • D: Document<any, {}, D>

    Parameters

    • name: string | number
    • schema: Schema<D, Model<any, any>, undefined>
    • Optional value: string

    Returns Model<D, {}>

  • Type parameters

    • T: Document<any, {}, T>

    • U: Model<T, {}, U>

    Parameters

    • name: string | number
    • schema: Schema<T, U, undefined>
    • Optional value: string

    Returns U

distinct

  • distinct(field: string, filter?: FilterQuery<IUserSchema>, callback?: (err: any, count: number) => void): Query<any[], IUserSchema, {}>
  • Creates a distinct query: returns the distinct values of the given field that match filter.

    Parameters

    • field: string
    • Optional filter: FilterQuery<IUserSchema>
    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<any[], IUserSchema, {}>

doesExist

  • doesExist(email: string): Promise<boolean>
  • Check if a user already exist with a given email address

    Parameters

    • email: string

      Email address to check

    Returns Promise<boolean>

    True if a user already exist with the given email address, false otherwise

    const email = '...'
    
    if(await User.doesExist(email)) {
            console.log('A user already exists with this email address !')
    }
    

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

ensureIndexes

  • ensureIndexes(callback?: (err: any) => void): Promise<void>
  • ensureIndexes(options?: any, callback?: (err: any) => void): Promise<void>
  • Sends createIndex commands to mongo for each index declared in the schema. The createIndex commands are sent in series.

    Parameters

    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

  • Parameters

    • Optional options: any
    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

estimatedDocumentCount

  • estimatedDocumentCount(options?: QueryOptions, callback?: (err: any, count: number) => void): Query<number, IUserSchema, {}>
  • Creates a estimatedDocumentCount query: counts the number of documents in the collection.

    Parameters

    • Optional options: QueryOptions
    • Optional callback: (err: any, count: number) => void
        • (err: any, count: number): void
        • Parameters

          • err: any
          • count: number

          Returns void

    Returns Query<number, IUserSchema, {}>

eventNames

  • eventNames(): (string | symbol)[]
  • Returns (string | symbol)[]

exists

  • exists(filter: FilterQuery<IUserSchema>): Promise<boolean>
  • exists(filter: FilterQuery<IUserSchema>, callback: (err: any, res: boolean) => void): void
  • Returns true if at least one document exists in the database that matches the given filter, and false otherwise.

    Parameters

    Returns Promise<boolean>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • callback: (err: any, res: boolean) => void
        • (err: any, res: boolean): void
        • Parameters

          • err: any
          • res: boolean

          Returns void

    Returns void

find

  • Creates a find query: gets a list of documents that match filter.

    Parameters

    Returns Query<IUserSchema[], IUserSchema, {}>

  • Parameters

    Returns Query<IUserSchema[], IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • Optional projection: any
    • Optional options: QueryOptions
    • Optional callback: (err: any, docs: IUserSchema[]) => void

    Returns Query<IUserSchema[], IUserSchema, {}>

findById

  • Finds a single document by its _id field. findById(id) is almost* equivalent to findOne({ _id: id }). If you want to query by a document's _id, use findById() instead of findOne().

    Parameters

    • id: any
    • Optional projection: any
    • Optional options: QueryOptions
    • Optional callback: (err: NativeError, doc: IUserSchema) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findByIdAndDelete

  • Creates a findByIdAndDelete query, filtering by the given _id.

    Parameters

    • Optional id: any
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findByIdAndRemove

  • Creates a findByIdAndRemove query, filtering by the given _id.

    Parameters

    • Optional id: any
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findByIdAndUpdate

  • findByIdAndUpdate(id: any, update: UpdateQuery<IUserSchema>, options: QueryOptions & { rawResult: true }, callback?: (err: any, doc: FindAndModifyWriteOpResultObject<IUserSchema>, res: any) => void): Query<FindAndModifyWriteOpResultObject<IUserSchema>, IUserSchema, {}>
  • findByIdAndUpdate(id: any, update: UpdateQuery<IUserSchema>, options: QueryOptions & { upsert: true } & { new: true } & QueryOptions & { upsert: true } & { returnOriginal: false }, callback?: (err: any, doc: IUserSchema, res: any) => void): Query<IUserSchema, IUserSchema, {}>
  • findByIdAndUpdate(id: any, update: UpdateQuery<IUserSchema>, callback?: (err: any, doc: IUserSchema, res: any) => void): Query<IUserSchema, IUserSchema, {}>
  • findByIdAndUpdate(id?: any, update?: UpdateQuery<IUserSchema>, options?: QueryOptions, callback?: (err: any, doc: IUserSchema, res: any) => void): Query<IUserSchema, IUserSchema, {}>
  • Creates a findOneAndUpdate query, filtering by the given _id.

    Parameters

    • id: any
    • update: UpdateQuery<IUserSchema>
    • options: QueryOptions & { rawResult: true }
    • Optional callback: (err: any, doc: FindAndModifyWriteOpResultObject<IUserSchema>, res: any) => void
        • (err: any, doc: FindAndModifyWriteOpResultObject<IUserSchema>, res: any): void
        • Parameters

          • err: any
          • doc: FindAndModifyWriteOpResultObject<IUserSchema>
          • res: any

          Returns void

    Returns Query<FindAndModifyWriteOpResultObject<IUserSchema>, IUserSchema, {}>

  • Parameters

    • id: any
    • update: UpdateQuery<IUserSchema>
    • options: QueryOptions & { upsert: true } & { new: true } & QueryOptions & { upsert: true } & { returnOriginal: false }
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

  • Parameters

    Returns Query<IUserSchema, IUserSchema, {}>

  • Parameters

    • Optional id: any
    • Optional update: UpdateQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findOne

  • Finds one document.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional projection: any
    • Optional options: QueryOptions
    • Optional callback: (err: NativeError, doc: IUserSchema) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findOneAndDelete

  • Creates a findOneAndDelete query: atomically finds the given document, deletes it, and returns the document as it was before deletion.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findOneAndRemove

  • Creates a findOneAndRemove query: atomically finds the given document and deletes it.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findOneAndReplace

  • findOneAndReplace(filter: FilterQuery<IUserSchema>, replacement: _AllowStringsForIds<LeanDocument<IUserSchema>>, options: QueryOptions & { upsert: true } & { new: true } & QueryOptions & { upsert: true } & { returnOriginal: false }, callback?: (err: any, doc: IUserSchema, res: any) => void): Query<IUserSchema, IUserSchema, {}>
  • findOneAndReplace(filter?: FilterQuery<IUserSchema>, replacement?: _AllowStringsForIds<LeanDocument<IUserSchema>>, options?: QueryOptions, callback?: (err: any, doc: IUserSchema, res: any) => void): Query<IUserSchema, IUserSchema, {}>
  • Creates a findOneAndReplace query: atomically finds the given document and replaces it with replacement.

    Parameters

    • filter: FilterQuery<IUserSchema>
    • replacement: _AllowStringsForIds<LeanDocument<IUserSchema>>
    • options: QueryOptions & { upsert: true } & { new: true } & QueryOptions & { upsert: true } & { returnOriginal: false }
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

  • Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional replacement: _AllowStringsForIds<LeanDocument<IUserSchema>>
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

findOneAndUpdate

  • Creates a findOneAndUpdate query: atomically find the first document that matches filter and apply update.

    Parameters

    • filter: FilterQuery<IUserSchema>
    • update: UpdateQuery<IUserSchema>
    • options: QueryOptions & { rawResult: true }
    • Optional callback: (err: any, doc: FindAndModifyWriteOpResultObject<IUserSchema>, res: any) => void
        • (err: any, doc: FindAndModifyWriteOpResultObject<IUserSchema>, res: any): void
        • Parameters

          • err: any
          • doc: FindAndModifyWriteOpResultObject<IUserSchema>
          • res: any

          Returns void

    Returns Query<FindAndModifyWriteOpResultObject<IUserSchema>, IUserSchema, {}>

  • Parameters

    • filter: FilterQuery<IUserSchema>
    • update: UpdateQuery<IUserSchema>
    • options: QueryOptions & { upsert: true } & { new: true } & QueryOptions & { upsert: true } & { returnOriginal: false }
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

  • Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional update: UpdateQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, doc: IUserSchema, res: any) => void

    Returns Query<IUserSchema, IUserSchema, {}>

geoSearch

  • Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional options: GeoSearchOptions
    • Optional callback: (err: NativeError, res: IUserSchema[]) => void

    Returns Query<IUserSchema[], IUserSchema, {}>

getByToken

  • getByToken(token: string): Promise<false | IUserSchema>
  • Get a user by its token

    Parameters

    • token: string

      JWT of the current session of the user, will be used to get the user id

    Returns Promise<false | IUserSchema>

    The User if there is any user matching (matching ID from the payload AND the token), false otherwise

    const token = '...'
    const user = await User.getByToken(token)
    
    if(user) {
            console.log('Session reconnected via token !')
    }
    

getMaxListeners

  • getMaxListeners(): number
  • Returns number

hashPassword

  • hashPassword(password: string): Promise<string>
  • Hash a plain text password

    Parameters

    • password: string

      Password to hash

    Returns Promise<string>

    The hashed password

    const password = '...'
    const hashed = await User.hashPassword(password)
    

hydrate

  • Shortcut for creating a new Document from existing raw data, pre-saved in the DB. The document returned has no paths marked as modified initially.

    Parameters

    • obj: any

    Returns IUserSchema

init

  • init(callback?: (err: any) => void): Promise<IUserSchema>
  • This function is responsible for building indexes, unless autoIndex is turned off. Mongoose calls this function automatically when a model is created using mongoose.model() or connection.model(), so you don't need to call it.

    Parameters

    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<IUserSchema>

insertMany

  • insertMany(doc: IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>
  • insertMany(doc: IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>, options?: InsertManyOptions): Promise<IUserSchema>
  • insertMany(docs: (IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>)[], options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>
  • insertMany(docs: (IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>)[], options?: InsertManyOptions): Promise<IUserSchema[]>
  • insertMany(doc: IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>, options?: InsertManyOptions, callback?: (err: NativeError, res: InsertManyResult | IUserSchema) => void): void
  • insertMany(docs: (IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>)[], options?: InsertManyOptions, callback?: (err: NativeError, res: InsertManyResult | IUserSchema[]) => void): void
  • Inserts one or more new documents as a single insertMany call to the MongoDB server.

    Parameters

    • doc: IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>
    • options: InsertManyOptions & { rawResult: true }

    Returns Promise<InsertManyResult>

  • Parameters

    Returns Promise<IUserSchema>

  • Parameters

    • docs: (IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>)[]
    • options: InsertManyOptions & { rawResult: true }

    Returns Promise<InsertManyResult>

  • Parameters

    Returns Promise<IUserSchema[]>

  • Parameters

    • doc: IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>
    • Optional options: InsertManyOptions
    • Optional callback: (err: NativeError, res: InsertManyResult | IUserSchema) => void
        • (err: NativeError, res: InsertManyResult | IUserSchema): void
        • Parameters

          Returns void

    Returns void

  • Parameters

    • docs: (IUserSchema | _AllowStringsForIds<LeanDocument<IUserSchema>>)[]
    • Optional options: InsertManyOptions
    • Optional callback: (err: NativeError, res: InsertManyResult | IUserSchema[]) => void
        • (err: NativeError, res: InsertManyResult | IUserSchema[]): void
        • Parameters

          • err: NativeError
          • res: InsertManyResult | IUserSchema[]

          Returns void

    Returns void

listIndexes

  • listIndexes(callback: (err: NativeError, res: any[]) => void): void
  • listIndexes(): Promise<any[]>
  • Lists the indexes currently defined in MongoDB. This may or may not be the same as the indexes defined in your schema depending on whether you use the autoIndex option and if you build indexes manually.

    Parameters

    • callback: (err: NativeError, res: any[]) => void
        • (err: NativeError, res: any[]): void
        • Parameters

          • err: NativeError
          • res: any[]

          Returns void

    Returns void

  • Returns Promise<any[]>

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

mapReduce

  • mapReduce<Key, Value>(o: MapReduceOptions<IUserSchema, Key, Value>, callback?: (err: any, res: any) => void): Promise<any>
  • Executes a mapReduce command.

    Type parameters

    • Key

    • Value

    Parameters

    • o: MapReduceOptions<IUserSchema, Key, Value>
    • Optional callback: (err: any, res: any) => void
        • (err: any, res: any): void
        • Parameters

          • err: any
          • res: any

          Returns void

    Returns Promise<any>

off

  • off(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

on

  • on(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

once

  • once(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

populate

  • populate(docs: any[], options: string | PopulateOptions | PopulateOptions[], callback?: (err: any, res: IUserSchema[]) => void): Promise<IUserSchema[]>
  • populate(doc: any, options: string | PopulateOptions | PopulateOptions[], callback?: (err: any, res: IUserSchema) => void): Promise<IUserSchema>
  • Populates document references.

    Parameters

    • docs: any[]
    • options: string | PopulateOptions | PopulateOptions[]
    • Optional callback: (err: any, res: IUserSchema[]) => void

    Returns Promise<IUserSchema[]>

  • Parameters

    • doc: any
    • options: string | PopulateOptions | PopulateOptions[]
    • Optional callback: (err: any, res: IUserSchema) => void

    Returns Promise<IUserSchema>

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

remove

  • remove(filter?: any, callback?: (err: NativeError) => void): Query<any, IUserSchema, {}>
  • Parameters

    • Optional filter: any
    • Optional callback: (err: NativeError) => void
        • (err: NativeError): void
        • Parameters

          • err: NativeError

          Returns void

    Returns Query<any, IUserSchema, {}>

removeAllListeners

  • removeAllListeners(event?: string | symbol): IUser
  • Parameters

    • Optional event: string | symbol

    Returns IUser

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): IUser
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns IUser

replaceOne

  • replaceOne(filter?: FilterQuery<IUserSchema>, replacement?: _AllowStringsForIds<LeanDocument<IUserSchema>>, options?: QueryOptions, callback?: (err: any, res: any) => void): Query<any, IUserSchema, {}>
  • Creates a replaceOne query: finds the first document that matches filter and replaces it with replacement.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional replacement: _AllowStringsForIds<LeanDocument<IUserSchema>>
    • Optional options: QueryOptions
    • Optional callback: (err: any, res: any) => void
        • (err: any, res: any): void
        • Parameters

          • err: any
          • res: any

          Returns void

    Returns Query<any, IUserSchema, {}>

setMaxListeners

  • setMaxListeners(n: number): IUser
  • Parameters

    • n: number

    Returns IUser

startSession

  • startSession(options?: SessionOptions, cb?: (err: any, session: ClientSession) => void): Promise<ClientSession>
  • Starts a MongoDB session for benefits like causal consistency, retryable writes, and transactions.

    Parameters

    • Optional options: SessionOptions
    • Optional cb: (err: any, session: ClientSession) => void
        • (err: any, session: ClientSession): void
        • Parameters

          • err: any
          • session: ClientSession

          Returns void

    Returns Promise<ClientSession>

syncIndexes

  • syncIndexes(options?: Record<string, unknown>): Promise<string[]>
  • syncIndexes(options: Record<string, unknown>, callback: (err: NativeError, dropped: string[]) => void): void
  • Makes the indexes in MongoDB match the indexes defined in this model's schema. This function will drop any indexes that are not defined in the model's schema except the _id index, and build any indexes that are in your schema but not in MongoDB.

    Parameters

    • Optional options: Record<string, unknown>

    Returns Promise<string[]>

  • Parameters

    • options: Record<string, unknown>
    • callback: (err: NativeError, dropped: string[]) => void
        • (err: NativeError, dropped: string[]): void
        • Parameters

          • err: NativeError
          • dropped: string[]

          Returns void

    Returns void

translateAliases

  • translateAliases(raw: any): any
  • Translate any aliases fields/conditions so the final query or document object is pure

    Parameters

    • raw: any

    Returns any

update

  • update(filter?: FilterQuery<IUserSchema>, update?: UpdateQuery<IUserSchema>, options?: QueryOptions, callback?: (err: any, res: any) => void): Query<UpdateWriteOpResult, IUserSchema, {}>
  • deprecated

    use updateOne or updateMany instead. Creates a update query: updates one or many documents that match filter with update, based on the multi option.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional update: UpdateQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, res: any) => void
        • (err: any, res: any): void
        • Parameters

          • err: any
          • res: any

          Returns void

    Returns Query<UpdateWriteOpResult, IUserSchema, {}>

updateMany

  • updateMany(filter?: FilterQuery<IUserSchema>, update?: UpdateQuery<IUserSchema>, options?: QueryOptions, callback?: (err: any, res: any) => void): Query<UpdateWriteOpResult, IUserSchema, {}>
  • Creates a updateMany query: updates all documents that match filter with update.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional update: UpdateQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, res: any) => void
        • (err: any, res: any): void
        • Parameters

          • err: any
          • res: any

          Returns void

    Returns Query<UpdateWriteOpResult, IUserSchema, {}>

updateOne

  • updateOne(filter?: FilterQuery<IUserSchema>, update?: UpdateQuery<IUserSchema>, options?: QueryOptions, callback?: (err: any, res: any) => void): Query<UpdateWriteOpResult, IUserSchema, {}>
  • Creates a updateOne query: updates the first document that matches filter with update.

    Parameters

    • Optional filter: FilterQuery<IUserSchema>
    • Optional update: UpdateQuery<IUserSchema>
    • Optional options: QueryOptions
    • Optional callback: (err: any, res: any) => void
        • (err: any, res: any): void
        • Parameters

          • err: any
          • res: any

          Returns void

    Returns Query<UpdateWriteOpResult, IUserSchema, {}>

validate

  • validate(callback?: (err: any) => void): Promise<void>
  • validate(optional: any, callback?: (err: any) => void): Promise<void>
  • validate(optional: any, pathsToValidate: string[], callback?: (err: any) => void): Promise<void>
  • Casts and validates the given object against this model's schema, passing the given context to custom validators.

    Parameters

    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

  • Parameters

    • optional: any
    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

  • Parameters

    • optional: any
    • pathsToValidate: string[]
    • Optional callback: (err: any) => void
        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns Promise<void>

watch

  • watch(pipeline?: Record<string, unknown>[], options?: ChangeStreamOptions): ChangeStream<any>
  • Watches the underlying collection for changes using MongoDB change streams.

    Parameters

    • Optional pipeline: Record<string, unknown>[]
    • Optional options: ChangeStreamOptions

    Returns ChangeStream<any>

where

  • Creates a Query, applies the passed conditions, and returns the Query.

    Parameters

    • path: string
    • Optional val: any

    Returns Query<IUserSchema[], IUserSchema, {}>

  • Parameters

    • obj: object

    Returns Query<IUserSchema[], IUserSchema, {}>

  • Returns Query<IUserSchema[], IUserSchema, {}>

Generated using TypeDoc