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.可以在现有数据库中创建新集合。
Click the Create Collection button.单击“创建集合”按钮。¶
From the Collections screen, click the Create Collection button.在“集合”屏幕中,单击“创建集合”按钮。
Enter the collection information.输入收集信息。¶
In the Create Collection dialog, enter the name of the collection to create.在“创建集合”对话框中,输入要创建的集合的名称。
If you want to create a capped collection, select the Capped Collection checkbox and enter the maximum bytes.如果要创建封顶集合,请选中“封顶集合”复选框并输入最大字节数。
If you want to use custom collation on the collection, select the Use Custom Collation checkbox and select the desired collation settings.如果要对集合使用自定义排序规则,请选中“使用自定义排序规则”复选框,然后选择所需的排序规则设置。
Click Create Collection to create the collection.单击“创建集合”以创建集合。¶
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.此时会出现一个确认对话框。
Confirm the collection to delete.确认要删除的集合。¶
In the dialog, enter the name of the collection to delete.在对话框中,输入要删除的集合的名称。
Click Drop Collection to drop the 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将显示该集合的“文档”选项卡。Compass provides the following collection information and functionality in the detailed view: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为您的架构设置验证规则
Tabbed View选项卡式视图¶
You can open multiple Collection Detail screens in separate tabs. 您可以在单独的选项卡中打开多个集合详细信息屏幕。To open a new tab to view collection details:要打开新选项卡以查看集合详细信息,请执行以下操作: