Collections集合
On this page本页内容
A collection is a grouping of MongoDB documents. 集合是一组MongoDB文档。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单个数据库中存在一个集合
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集合中的文档数NoteCompass 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.将鼠标悬停在“排序规则”横幅上,可以查看该集合的属性。
Create a Collection创建集合
You can create new collections in an existing database.您可以在现有数据库中创建新集合。
Drop a Collection删除集合
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管理文档Import and Export Data to / from the collection将数据导入集合/从集合导出数据Aggregation Pipeline Builder聚合管道生成器Schema Analysis架构分析View Query Performance查看查询性能Manage Indexes管理索引Set Validation Rules for Your Schema为架构设置验证规则
Data Lake Limitations数据湖限制
The following functionality is not available if you are connected to a Data Lake:如果连接到数据湖,则以下功能不可用:
Import data into a collection将数据导入集合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:要打开新选项卡以查看集合详细信息,请执行以下操作: