Docs Menu

database.collection()

On this page

  • Definition
  • Usage
  • Example
  • Parameters
  • Return Value
database.collection()

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

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");

The database.collection() action 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.

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

Give Feedback
© 2021 MongoDB, Inc.

About

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