Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Implements

Index

Constructors

Methods

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

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

    • event: string | symbol

    Returns Function[]

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

    • event: string | symbol

    Returns Function[]

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

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

    Returns boolean

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

    • type: string | symbol

    Returns number

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

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

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

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

          • Rest ...args: any[]

          Returns void

    Returns <internal>.Connection

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

  • Returns a promise that resolves when this connection successfully connects to MongoDB

    Returns Promise<<internal>.Connection>

  • Closes the connection

    Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    • Optional force: boolean

    Returns Promise<void>

  • Closes and destroys the connection. Connection once destroyed cannot be reopened

    Parameters

    Returns void

  • Parameters

    Returns void

  • Parameters

    • Optional force: boolean

    Returns Promise<void>

  • Removes the model named name from this connection, if it exists. You can use this function to clean up any models you created in your tests to prevent OverwriteModelErrors.

    Parameters

    • name: string | RegExp

    Returns <internal>.Connection

  • dropCollection(collection: string, callback: CallbackWithoutResult): void
  • dropCollection(collection: string): Promise<void>
  • Helper for dropCollection(). Will delete the given collection, including all documents and indexes.

    Parameters

    Returns void

  • Parameters

    • collection: string

    Returns Promise<void>

  • Helper for dropDatabase(). Deletes the given database, including all collections, documents, and indexes.

    Parameters

    Returns void

  • Returns Promise<void>

  • get(key: string): any
  • Gets the value of the option key.

    Parameters

    • key: string

    Returns any

  • modelNames(): string[]
  • Returns an array of model names created on this connection.

    Returns string[]

  • Declares a plugin executed on all schemas you pass to conn.model()

    Type Parameters

    Parameters

    • fn: ((schema: S, opts?: any) => void)
        • (schema: S, opts?: any): void
        • Parameters

          • schema: S
          • Optional opts: any

          Returns void

    • Optional opts: O

    Returns <internal>.Connection

  • set(key: string, value: any): any
  • Sets the value of the option key.

    Parameters

    • key: string
    • value: any

    Returns any

  • Set the MongoDB driver MongoClient instance that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to reuse it.

    Parameters

    Returns <internal>.Connection

  • Makes the indexes in MongoDB match the indexes defined in every 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

    Returns void

  • Parameters

    Returns Promise<ConnectionSyncIndexesResult>

  • Requires MongoDB >= 3.6.0. Executes the wrapped async function in a transaction. Mongoose will commit the transaction if the async function executes successfully and attempt to retry if there was a retryable error.

    Parameters

    Returns Promise<void>

  • Switches to a different database using the same connection pool.

    Parameters

    • name: string
    • Optional options: { useCache?: boolean; noListener?: boolean }
      • Optional useCache?: boolean
      • Optional noListener?: boolean

    Returns <internal>.Connection

Properties

errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

captureRejectionSymbol: typeof captureRejectionSymbol
captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

defaultMaxListeners: number
collections: {}

A hash of the collections associated with this connection

Type declaration

config: any

A hash of the global options that are associated with this connection

db: Db

The mongodb.Db instance, set when the connection is opened

host: string

The host name portion of the URI. If multiple hosts, such as a replica set, this will contain the first host name in the URI

id: number

A number identifier for this connection. Used for debugging when you have multiple connections.

models: Readonly<{}>

A POJO containing a map from model names to models. Contains all models that have been added to this connection using Connection#model().

name: string

The name of the database this connection points to.

pass: string

The password specified in the URI

port: number

The port portion of the URI. If multiple hosts, such as a replica set, this will contain the port from the first host name in the URI.

plugins: any[]

The plugins that will be applied to all models created on this connection.

readyState: ConnectionStates

Connection ready state

  • 0 = disconnected
  • 1 = connected
  • 2 = connecting
  • 3 = disconnecting
  • 99 = uninitialized
user: string

The username specified in the URI

Generated using TypeDoc