Skip to main content
Version: 6.3

MongoConnection

Hierarchy

Index

Constructors

constructor

Methods

aggregate

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

    • T: object = any

    Parameters

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

    Returns Promise<T[]>

begin

  • Parameters

    Returns Promise<ClientSession>

bulkUpdateMany

  • Type parameters

    • T: object

    Parameters

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

    Returns Promise<QueryResult<T>>

checkConnection

  • checkConnection(): Promise<{ error?: Error; ok: boolean; reason?: string }>
  • Are we connected to the database


    Returns Promise<{ error?: Error; ok: boolean; reason?: string }>

close

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


    Parameters

    • optionalforce: boolean

    Returns Promise<void>

commit

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

    Returns Promise<Collection<T>>

deleteMany

  • 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

    Returns Promise<boolean>

ensureConnection

  • ensureConnection(): Promise<void>
  • Ensure the connection exists, this is used to support lazy connect when using MikroORM.initSync()


    Returns Promise<void>

execute

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

    • query: string

    Returns Promise<any>

find

getClient

  • getClient(): MongoClient
  • Returns MongoClient

getClientUrl

  • getClientUrl(): string
  • Returns string

getCollection

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

    • T: object

    Parameters

    Returns Collection<T>

getConnectionOptions

  • 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

  • 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

setMetadata

  • Parameters

    Returns void

setPlatform

  • Parameters

    Returns void

transactional

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

    • T

    Parameters

    Returns Promise<T>

updateMany

  • Type parameters

    • T: object

    Parameters

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

    Returns Promise<QueryResult<T>>