Options
All
  • Public
  • Public/Protected
  • All
Menu

The class that handles the cleaning code, doing the bigger part of the job.

Hierarchy

  • Cleaner

Index

Constructors

  • The constructor of the class.

    Parameters

    • uri: string

      The uri for the MongoDB database.

    • connectionOptions: MongoClientOptions

      The connection options to the MongoDB.

    • options: Required<MongoCleanerOptions>

      The options for the cleaner.

    Returns Cleaner

Properties

connection: MongoClient

The MongoDB connection.

connectionOptions: MongoClientOptions

The connection options to the MongoDB.

logger: Logger

The instance of the logger.

options: Required<MongoCleanerOptions>

The options for the cleaner.

uri: string

The uri for the MongoDB database.

Methods

  • clean(): Promise<void>
  • Does the whole process of cleaning the databases, based on the options given to the class constructor.

    throws

    MongoCleanerCleanError

    Returns Promise<void>

  • cleanCollection(database: string, collection: string, attempts: number): Promise<void>
  • Cleans a collection, by removing it.

    throws

    MongoCleanerCleanError

    Parameters

    • database: string

      The database of the collection.

    • collection: string

      The collection to empty.

    • attempts: number

      The number of remaining attempts to clean the collection, after which an error could be thrown.

    Returns Promise<void>

  • cleanDatabase(database: string, attempts: number): Promise<void>
  • Cleans a database, by removing it.

    throws

    MongoCleanerCleanError

    Parameters

    • database: string

      The database to clean.

    • attempts: number

      The number of remaining attempts to clean the database, after which an error could be thrown.

    Returns Promise<void>

  • cleanDatabases(databases: string[]): Promise<void>
  • Cleans an array of databases.

    Parameters

    • databases: string[]

      The database to be cleaned.

    Returns Promise<void>

  • connect(): Promise<void>
  • The method for connecting to the database.

    throws

    MongoCleanerConnectionError

    Returns Promise<void>

  • disconnect(): Promise<void>
  • The method for disconnecting to the database.

    throws

    MongoCleanerDisconnectionError

    Returns Promise<void>

  • emptyCollection(database: string, collection: string, attempts: number): Promise<void>
  • Empties a collection, by removing all its documents.

    throws

    MongoCleanerCleanError

    Parameters

    • database: string

      The database of the collection.

    • collection: string

      The collection to empty.

    • attempts: number

      The number of remaining attempts to empty the collection, after which an error could be thrown.

    Returns Promise<void>

  • emptyDatabase(database: string): Promise<void>
  • Empties a database, by removing all its collections.

    Parameters

    • database: string

      The database to empty.

    Returns Promise<void>

  • filterDatabase(database: string): boolean
  • A method that passed a database name, based on the instance options, reurns true if the database is to be cleaned or false otherwise.

    Parameters

    • database: string

      The database name.

    Returns boolean

    If the database is to be cleaned.

  • getCollections(database: string): Promise<string[]>
  • Fetches from MongoDB all the collections of a database and returns the ones that are to be cleaned.

    throws

    MongoCleanerListCollectionsError

    Parameters

    • database: string

      The database whose collections will be fetched.

    Returns Promise<string[]>

    The collections of the database that are to be cleaned.

  • getDatabases(): Promise<string[]>
  • Fetches from MongoDB all the databases and returns the ones that are to be cleaned.

    throws

    MongoCleanerListDatabasesError

    Returns Promise<string[]>

    The databases that are to be cleaned.

  • sleep(millisecond: number): Promise<void>
  • A method returning a promise that waits the passed number of milliseconds.

    Parameters

    • millisecond: number

      The number of milliseconds.

    Returns Promise<void>

Generated using TypeDoc