Skip to main content
Version: 5.9

MongoConnection

Hierarchy

  • Connection
    • MongoConnection

Index

Constructors

constructor

  • new MongoConnection(config: Configuration<IDatabaseDriver<Connection>>, options?: ConnectionOptions, type?: ConnectionType): MongoConnection
  • Parameters

    • config: Configuration<IDatabaseDriver<Connection>>
    • optionaloptions: ConnectionOptions
    • type: ConnectionType = 'write'

    Returns MongoConnection

Methods

aggregate

  • aggregate<T>(collection: string, pipeline: any[], ctx?: ClientSession): Promise<T[]>
  • Type parameters

    • T: object = any

    Parameters

    • collection: string
    • pipeline: any[]
    • optionalctx: ClientSession

    Returns Promise<T[]>

begin

  • begin(options?: { ctx?: ClientSession; eventBroadcaster?: TransactionEventBroadcaster; isolationLevel?: IsolationLevel } & TransactionOptions): Promise<ClientSession>
  • Parameters

    • options: { ctx?: ClientSession; eventBroadcaster?: TransactionEventBroadcaster; isolationLevel?: IsolationLevel } & TransactionOptions = {}

    Returns Promise<ClientSession>

bulkUpdateMany

  • bulkUpdateMany<T>(collection: string, where: FilterQuery<T>[], data: Partial<T>[], ctx?: ClientSession, upsert?: boolean, upsertOptions?: UpsertOptions<T>): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • where: FilterQuery<T>[]
    • data: Partial<T>[]
    • optionalctx: ClientSession
    • optionalupsert: boolean
    • optionalupsertOptions: UpsertOptions<T>

    Returns Promise<QueryResult<T>>

close

  • close(force?: boolean): Promise<void>
  • Closes the database connection (aka disconnect)


    Parameters

    • optionalforce: boolean

    Returns Promise<void>

commit

  • commit(ctx: ClientSession, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>
  • Parameters

    • ctx: ClientSession
    • optionaleventBroadcaster: TransactionEventBroadcaster

    Returns Promise<void>

connect

  • connect(): Promise<void>
  • Establishes connection to database


    Returns Promise<void>

countDocuments

  • countDocuments<T>(collection: string, where: FilterQuery<T>, ctx?: ClientSession): Promise<number>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • where: FilterQuery<T>
    • optionalctx: ClientSession

    Returns Promise<number>

createCollection

  • createCollection<T>(name: EntityName<T>): Promise<Collection<T>>
  • Type parameters

    • T: object

    Parameters

    • name: EntityName<T>

    Returns Promise<Collection<T>>

deleteMany

  • deleteMany<T>(collection: string, where: FilterQuery<T>, ctx?: ClientSession): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • where: FilterQuery<T>
    • optionalctx: ClientSession

    Returns Promise<QueryResult<T>>

dropCollection

  • dropCollection(name: EntityName<Partial<any>>): Promise<boolean>
  • Parameters

    • name: EntityName<Partial<any>>

    Returns Promise<boolean>

execute

  • execute(query: string): Promise<any>
  • Parameters

    • query: string

    Returns Promise<any>

find

  • find<T>(collection: string, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: ClientSession): Promise<EntityData<T>[]>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • where: FilterQuery<T>
    • optionalorderBy: QueryOrderMap<T> | QueryOrderMap<T>[]
    • optionallimit: number
    • optionaloffset: number
    • optionalfields: string[]
    • optionalctx: ClientSession

    Returns Promise<EntityData<T>[]>

getClient

  • getClient(): MongoClient
  • Returns MongoClient

getClientUrl

  • getClientUrl(): string
  • Returns string

getCollection

  • getCollection<T>(name: EntityName<T>): Collection<T>
  • Type parameters

    • T: object

    Parameters

    • name: EntityName<T>

    Returns Collection<T>

getConnectionOptions

  • getConnectionOptions(): MongoClientOptions & ConnectionConfig
  • Returns MongoClientOptions & ConnectionConfig

getDb

  • getDb(): Db
  • Returns Db

getDefaultClientUrl

  • getDefaultClientUrl(): string
  • Returns default client url for given driver (e.g. mongodb://127.0.0.1:27017 for mongodb)


    Returns string

getPlatform

  • getPlatform(): Platform
  • Returns Platform

insertMany

  • insertMany<T>(collection: string, data: Partial<T>[], ctx?: ClientSession): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • data: Partial<T>[]
    • optionalctx: ClientSession

    Returns Promise<QueryResult<T>>

insertOne

  • insertOne<T>(collection: string, data: Partial<T>, ctx?: ClientSession): Promise<QueryResult<T>>
  • Type parameters

    • T: object

    Parameters

    • collection: string
    • data: Partial<T>
    • optionalctx: ClientSession

    Returns Promise<QueryResult<T>>

isConnected

  • isConnected(): Promise<boolean>
  • Are we connected to the database


    Returns Promise<boolean>

listCollections

  • listCollections(): Promise<string[]>
  • Returns Promise<string[]>

rollback

  • rollback(ctx: ClientSession, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>
  • Parameters

    • ctx: ClientSession
    • optionaleventBroadcaster: TransactionEventBroadcaster

    Returns Promise<void>

setMetadata

  • setMetadata(metadata: MetadataStorage): void
  • Parameters

    • metadata: MetadataStorage

    Returns void

setPlatform

  • setPlatform(platform: Platform): void
  • Parameters

    • platform: Platform

    Returns void

transactional

  • transactional<T>(cb: (trx: ClientSession) => Promise<T>, options?: { ctx?: ClientSession; eventBroadcaster?: TransactionEventBroadcaster; isolationLevel?: IsolationLevel } & TransactionOptions): Promise<T>
  • Type parameters

    • T

    Parameters

    • cb: (trx: ClientSession) => Promise<T>
      • options: { ctx?: ClientSession; eventBroadcaster?: TransactionEventBroadcaster; isolationLevel?: IsolationLevel } & TransactionOptions = {}

      Returns Promise<T>

    updateMany

    • updateMany<T>(collection: string, where: FilterQuery<T>, data: Partial<T>, ctx?: ClientSession, upsert?: boolean, upsertOptions?: UpsertOptions<T>): Promise<QueryResult<T>>
    • Type parameters

      • T: object

      Parameters

      • collection: string
      • where: FilterQuery<T>
      • data: Partial<T>
      • optionalctx: ClientSession
      • optionalupsert: boolean
      • optionalupsertOptions: UpsertOptions<T>

      Returns Promise<QueryResult<T>>