Options
All
  • Public
  • Public/Protected
  • All
Menu

The MongoScanner class, to retrieve the database schema or to list databases and collections of a MongoDB database.

Hierarchy

  • MongoScanner

Index

Constructors

  • The constructor of the MongoScanner class. The params are the uri and options for the database connections. The connection is not established by the constructor, the connection parameters are only saved in the MongoScanner instance.

    Parameters

    • Optional uri: string

      The string uri of the mongodb connection. Default: 'mongodb://localhost:27017'.

    • Optional connectionOptions: any

      The options object of the mongodb connection. The npm mongodb module is used under the hood and this is the object provided to MongoClient. Default: { }.

    • Optional options: ScanOptions

      The options that will be used as a fallback for the ScanOptions. For all the keys that will not be present in the options provided to a method that retrieves database or collections, the values provided here will be used instead of the default ones. Default: { }.

    Returns MongoScanner

Methods

  • clearCache(): void
  • Clears the cache, which contains the results of the previous executions of the MongoScanner instance.

    Returns void

  • endConnection(): Promise<void>
  • Closes an already open persistent connection.

    Returns Promise<void>

  • Retrieves the schema of a mongodb database as a promise to a DatabaseSchema object.

    Parameters

    Returns Promise<DatabaseSchema>

    A promise to a DatabaseSchema object representing the database schema. The keys are the databases and their values the collections of the database as an array of strings

  • listCollections(database: string, options?: ScanOptions): Promise<string[]>
  • Retrieves the collections of the specified database as a promise to an array of strings.

    Parameters

    • database: string

      The database whose collections will be exported.

    • Optional options: ScanOptions

      The ScanOptions options.

    Returns Promise<string[]>

    A promise to an array of strings containing the retrieved collections.

  • listDatabases(options?: ScanOptions): Promise<string[]>
  • Retrieves the databases of a mongodb as a promise to an array of strings.

    Parameters

    Returns Promise<string[]>

    A promise to an array of strings containing the retrieved databases.

  • startConnection(): Promise<void>
  • Starts a persistent connection to mongodb. By default, all methods that retrieve databases or collections from the mongodb open a connection before beginning and close it after finishing. This method allows you to have a persistent connection instead and is useful if you need to perform more than an operation and do not want to open and close connections for each of them.

    Returns Promise<void>

Generated using TypeDoc