A collection is a grouping of MongoDB documents. Documents within a collection can have different fields. A collection is the equivalent of a table in a relational database system. A collection exists within a single database.集合是一组MongoDB文档。集合中的文档可以有不同的字段。集合相当于关系数据库系统中的表。一个集合存在于单个数据库中。
Collections Screen集合屏幕
The Collections screen lists the existing collections and views in the selected database. Each list item includes the name and other general information for the collection or view.“集合”屏幕列出了所选数据库中的现有集合和视图。每个列表项都包括集合或视图的名称和其他一般信息。
To access the Collections screen for a database, from the Databases screen either:要访问数据库的“集合”屏幕,请从“数据库”屏幕执行以下操作之一:
Click a Database Name in the main Databases view, or在主“数据库”视图中单击“数据库名称”,或Click a database in the left navigation.单击左侧导航中的数据库。

Collection Information集合信息
The Collections screen displays the following information for each collection in the selected database:“集合”屏幕显示所选数据库中每个集合的以下信息:
Collection name集合名称Number of documents in the collection集合中的文档数量Note
Compass bases the document count that appears on the Collections screen on cached metadata using collStats.Compass使用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.使用db.collection.countDocuments()方法进行最准确的文档计数。Average size of documents in the collection集合中文档的平均大小Total size of all documents in the collection集合中所有文档的总大小Number of indexes on the collection集合上的索引数Total size of all indexes on the collection集合上所有索引的总大小Collation properties for the collection. Hover over a Collation banner to view the properties for that collection.集合的排序规则属性。将鼠标悬停在“排序规则”横幅上以查看该集合的属性。
Note
If you're granted a custom role or privilege to a collection but lack privileges to list server namespaces, Compass lists the collection in the Collections screen with an empty folder icon , and the collection name turns grey. Compass displays the collection this way even if it doesn't exist.如果您被授予了集合的自定义角色或权限,但缺乏列出服务器命名空间的权限,Compass会在“集合”屏幕中列出该集合,并显示一个空文件夹图标,集合名称将变为灰色。Compass以这种方式显示集合,即使它不存在。
To avoid seeing these collections, you can disable the Infer Additional Namespaces from Privileges setting in the Compass settings panel.为了避免看到这些集合,您可以在Compass设置面板中禁用“从权限推断其他命名空间”设置。
Create a Collection创建集合
You can create new collections in an existing database.您可以在现有数据库中创建新集合。
Click the Create Collection button.单击“创建集合”按钮。
From the Collections screen, click the Create Collection button. Alternatively, you can right-click anywhere on the left-hand menu and select Create collection from the dropdown.在“集合”屏幕中,单击“创建集合”按钮。或者,您可以右键单击左侧菜单上的任何位置,然后从下拉列表中选择“创建集合”。
Drop a Collection丢弃集合
Click the trash can icon to delete a collection.单击垃圾桶图标删除集合。
From the Collections screen, click on the trash can for the collection to delete. A confirmation dialog appears.在“集合”屏幕中,单击要删除集合的垃圾桶。此时会出现一个确认对话框。
You can also right-click the collection name and select Drop collection from the drop-down menu.您还可以右键单击集合名称,然后从下拉菜单中选择“删除集合”。
Collection Details集合详细信息
The Collection Detail screen shows detailed information for a collection, including the documents the collection contains. To see collection details, either:“集合详细信息”屏幕显示集合的详细信息,包括集合包含的文档。要查看集合详细信息,请执行以下操作之一:
Click a Collection Name in the main Collections screen, or在主“集合”屏幕中单击“集合名称”,或Click a collection in the left navigation.单击左侧导航中的集合。Open the collection in a new tab.在新选项卡中打开集合。
After you select a collection, Compass shows you that collection's Documents tab. Compass provides the following collection information and functionality in the detailed view:选择集合后,Compass将显示该集合的“文档”选项卡。Compass在详细视图中提供以下集合信息和功能:
Manage Documents in Compass在Compass中管理文档Import and Export Data导入到到集合中、从集合中导出数据to and from the collectionCreate an Aggregation Pipeline创建聚合管道Schema Analysis模式分析View Query Performance查看查询性能Manage Indexes管理索引Set Validation Rules for Your Schema为架构设置验证规则
Tabbed View标签化视图
You can open multiple Collection Detail screens in separate tabs. To open a new tab to view collection details:您可以在单独的选项卡中打开多个“集合详细信息”屏幕。要打开新选项卡以查看集合详细信息,请执行以下操作:
Limitations局限性
Creating and dropping collections is not permitted in MongoDB Compass Readonly Edition.MongoDB Compass只读版不允许创建和删除集合。