Skip to main content
Version: 6.4

MongoConnection

Hierarchy

Index

Constructors

constructor

Methods

aggregate

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

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

    Returns Promise<T[]>

begin

  • Parameters

    Returns Promise<ClientSession>

bulkUpdateMany

  • Parameters

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

    Returns Promise<QueryResult<T>>

checkConnection

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


    Returns Promise<{ ok: true } | { error?: Error; ok: false; 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(collection: string, where: FilterQuery<T>, ctx?: ClientSession): Promise<number>
  • Parameters

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

    Returns Promise<number>

createCollection

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

    Returns Promise<Collection<T>>

deleteMany

dropCollection

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

    Returns Promise<boolean>

inheritedensureConnection

  • 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

  • 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

inheritedgetPlatform

  • Returns Platform

insertMany

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

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

    Returns Promise<QueryResult<T>>

insertOne

  • insertOne(collection: string, data: Partial<T>, ctx?: ClientSession): Promise<QueryResult<T>>
  • 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

inheritedsetMetadata

  • Parameters

    Returns void

inheritedsetPlatform

  • Parameters

    Returns void

transactional

  • Parameters

    Returns Promise<T>

updateMany

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

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

    Returns Promise<QueryResult<T>>