Docs Menu


On this page

  • Definition
  • Usage
  • Example
  • Parameters
  • Return Value

Return a database handle object that represents a database in a linked MongoDB data source. Call database.collection() on the database handle to retrieve a collection handle.

To call the mongodb.db() action from a function, instantiate a MongoDB service client from context then call the client's db() method.

const mongodb ="myMongoDBCluster");
const db = mongodb.db("myDB");

The db() action has the following form:


Database Name

name: <string>
The name of the database. The database must exist in the linked cluster associated with the MongoDB service client.

The mongodb.db() action returns a database object that allows you to access collections in the specified database.

See database.collection()

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.