Navigation

mongodb.db()

Definition

mongodb.db()

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

Usage

Example

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 = context.services.get("myMongoDBCluster");
const db = mongodb.db("myDB");

Parameters

The db() action has the following form:

db(name)
Parameter Description

Database Name

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

Return Value

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

See database.collection()