Navigation

database.collection()

Definition

database.collection()

Return a collection handle object that represents a collection in a database.

Usage

Example

To call the database.collection() action from a Function, get a database handle with mongodb.db() then call the handle’s collection() method.

const collection = mongodb.db("myDB").collection("myCollection");

To call the database.collection() action from a JavaScript SDK, use the RemoteMongoDatabase.collection() method.

const collection = mongodb.db("myDB").collection("myCollection");

To call the database.collection() action from the Java/Android SDK, use the RemoteMongoDatabase.collection() method.

RemoteMongoDatabase db = mongodb.getDatabase("myDB").getCollection("myCollection");

To call the database.collection() action from the Swift/iOS SDK, use the RemoteMongoDatabase.collection() method.

RemoteMongoDatabase db = mongodb.db("myDB").collection("myCollection")

Parameters

The database.collection() action has the following form:

collection(name)

The collection() method has the following form:

collection(name)

The getCollection() method has the following form:

getCollection(name)

The collection() method has the following form:

collection(name)
Parameter Description

Collection Name

name: <string>
The name of the collection. The collection must exist in the database associated with the database handle object.

Return Value

The database.collection() action returns a collection object that allows you to query the specified collection.

The RemoteMongoDatabase.collection() method returns a RemoteMongoCollection object that allows you to query the specified collection.

The RemoteMongoDatabase.getCollection() method returns a RemoteMongoCollection object that allows you to query the specified collection.

The RemoteMongoDatabase.collection() method returns a RemoteMongoCollection object that allows you to query the specified collection.