Skip to content

Latest commit

 

History

History
88 lines (46 loc) · 1.92 KB

database.md

File metadata and controls

88 lines (46 loc) · 1.92 KB

Database

Events

Database is an event emitter that emits the following events:

  • error - Emitted if there is an error during connection with the error as its argument
  • connect - Emitted once the connection has been established
  • close - Emitted when the connection is forcibly closed

Properties

Each instance of Database has the following properties:

  • ObjectId - Constructor for making ObjectIds from strings

Methods

database.collection(colName)

Returns Collection

Get a collection by name

database.close(force = false)

Returns Promise<void>

Close the database connection

database.runCommand(command)

Returns Promise<any>

Execute a command

database.listCollections()

Returns Promise<Array<Object>>

Get a list of collections with info about each one

database.getCollectionNames()

Returns Promise<Array<string>>

Get a list of all the collections

database.createCollection(name, opts = {})

Returns Promise<void>

Create a collection by name

database.stats(scale = 1)

Returns Promise<Object>

database.dropDatabase()

Returns Promise<void>

database.createUser(usr)

Returns Promise<void>

database.dropUser(username)

Returns Promise<void>

database.eval(fn, ...args)

Returns Promise<any>

database.getLastErrorObj()

Returns Promise<Object>

database.getLastError()

Returns Promise<string>

database.toString()

Returns string

database._getConnection()

Returns Promise