Create, View, Drop, and Shard Collections
You can use the Atlas UI to manage the collections in your database deployments.
Required Roles
The following table describes the roles required to perform various actions to a database in the Atlas UI:
Action | Required Role(s) |
---|---|
Create Collections | One of the following roles: |
View Collections | At least the Project Data Access Read Only role. |
Drop Collections | One of the following roles: |
Shard Collections | One of the following roles: |
Create a Collection
To create the first collection in a new database, see Create a Database.
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:
Enter the Collection Name.
For more information on MongoDB collection names, see Naming Restrictions.
Optional. Specify a capped collection.
Select whether the collection is a capped collection. If you select to create a capped collection, specify the maximum size in bytes.
Optional. Specify a time series collection.
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.
View Collections
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:
To view the collections in a particular database, click on the name of the database.
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.
Drop a Collection
To drop a collection, including its documents and indexes, through the Atlas UI:
Shard a Collection
If you have large data sets and perform high throughput operations, you can shard a collection to distribute data across the shards.
To shard a collection through the Atlas UI:
Connect to MongoDB from mongosh
.
See Connect via mongosh
.
Enable sharding for the databases you want to shard.
To enable sharding, run the following command:
sh.enableSharding("<database-name>")
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.
Optional: Create an index on the shard key if the collection that you wish to shard has data and is not empty.
To create an index on the shard key, run the following command:
db.<collection-name>.createIndex({<shard_key_definition>})
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:
Shard the collection that you want to shard.
To shard a collection, run the following command:
sh.shardCollection(“<database>.<collection>”, { "<indexed-field>" : 1 } )
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.