Docs Menu

Docs HomeMongoDB Atlas

Create, View, Drop, and Shard Collections

On this page

  • Required Roles
  • Create a Collection
  • View Collections
  • Drop a Collection
  • Shard a Collection

You can use the Atlas UI to manage the collections in your database deployments.

The following table describes the roles required to perform various actions to a database in the Atlas UI:

Action
Required Role(s)
Create Collections
View Collections
Drop Collections

One of the following roles:

Shard Collections

One of the following roles:

Tip

To create the first collection in a new database, see Create a Database.

Important

You cannot create new collections on the config and system databases. Atlas will deprecate writing to existing collections on these databases in the near future.

To create a collection in an existing database through the Atlas UI:

1
2

Either select or hover over the database to drop and click on the plus sign + icon.

3

For more information on MongoDB collection names, see Naming Restrictions.

4

Select whether the collection is a capped collection. If you select to create a capped collection, specify the maximum size in bytes.

5

Select whether the collection is a time series collection. If you select to create a time series collection, specify the time field and granularity. You can optionally specify the meta field and the time for old data in the collection to expire.

6

Upon successful creation, the collection appears underneath the database in the Atlas UI.

From the Collections tab, you can view the databases and collections in the deployment. Atlas shows the databases in the left pane of the Atlas UI:

Screenshot highlighting databases.

To view the collections in a particular database, click on the name of the database.

Note

Atlas bases the document count that appears on the Collections tab on cached metadata using collStats. This count might differ from the actual document count in the collection. For example, an unexpected shutdown can throw off the count. Use the db.collection.countDocuments() method for the most accurate document count.

To drop a collection, including its documents and indexes, through the Atlas UI:

1

Either select or hover of the collection to drop and click on its trash can icon.

2

Confirm by typing the name of the collection, and click Drop.

If you have large data sets and perform high throughput operations, you can shard a collection to distribute data across the shards.

Note

Before you start, you must have the following:

To shard a collection through the Atlas UI:

1

See Connect via mongosh.

2

To enable sharding, run the following command:

sh.enableSharding("<database-name>")

Example

To enable sharding for the sample_analytics dataset:

sh.enableSharding("sample_analytics")

To learn more, see Enable Sharding for a Database in the MongoDB manual.

3

To create an index on the shard key, run the following command:

db.<collection-name>.createIndex({<shard_key_definition>})

Example

To create an index on the shard key for the sample_analytics.customers collection:

db.sample_analytics.runCommand( { createIndexes: "customers", indexes: [ { key: { "username": 1 }, "name": "usernameIndex" }], "commitQuorum": "majority" } )

To learn more, see:

4

To shard a collection, run the following command:

sh.shardCollection(“<database>.<collection>”, { "<indexed-field>" : 1 } )

Example

To shard the sample_analytics.customers collection:

sh.shardCollection("sample_analytics.customers",{"username":1})

To learn more, see Shard a Collection in the MongoDB manual.

←  Create, View, and Drop DatabasesCreate, View, Update, and Delete Documents →
Share Feedback
© 2023 MongoDB, Inc.

About

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