- Stitch >
- MongoDB Atlas >
- Reference >
- MongoDB Actions
mongodb.db()¶
On this page
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.
Note
The mongodb.db()
action is available on MongoDB service
clients. You can instantiate a service client with the
context.services.get(serviceName)
method in functions or the getServiceClient()
action in a client SDK.
Usage¶
Example¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
To call the mongodb.db()
action from a Function, instantiate a MongoDB service client from
context then call
the client’s db()
method.
To call the mongodb.db()
action from a JavaScript SDK, use
the RemoteMongoClient.db() method.
To call the collection.db()
action from the Java/Android
SDK, use the RemoteMongoClient.getDatabase() method.
To call the mongodb.db()
action from the Swift/iOS
SDK, use the RemoteMongoClient.db() method.
Parameters¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
The db()
action is available on MongoDB service
clients returned from
context.services.get(serviceName)
as the db
method, which has the following form:
The db()
action has the following form:
The db() method has the following form:
The getDatabase() method has the following form:
The db() method has the following form:
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¶
- Functions
- JavaScript SDK
- Android SDK
- iOS SDK
The mongodb.db()
action returns a database object that
allows you to access collections in the specified database.
The RemoteMongoClient.db() method returns a RemoteMongoDatabase object that allows you to access collections in the specified database.
The RemoteMongoClient.getDatabase() method returns a RemoteMongoDatabase object that allows you to access collections in the specified database.
The RemoteMongoClient.db() method returns a RemoteMongoDatabase object that allows you to access collections in the specified database.