Docs HomeMongoDB Compass

Collections集合

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.单击左侧导航中的数据库。
Select database

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.将鼠标悬停在“排序规则”横幅上,可以查看该集合的属性。

Create a Collection创建集合

You can create new collections in an existing database.您可以在现有数据库中创建新集合。

1

Click the Create Collection button.单击“创建集合”按钮。

From the Collections screen, click the Create Collection button.在“集合”屏幕中,单击“创建集合”按钮。

2

Enter the collection information.输入集合信息。

In the Create Collection dialog, enter the name of the collection to create.在“创建集合”对话框中,输入要创建的集合的名称。

Compass also provides you with Advanced Collection Options. Compass还为您提供“高级集合选项”。You can select from the following:您可以从以下选项中进行选择:

3

Click Create Collection to create the collection.单击“创建集合”以创建集合。

Drop a Collection删除集合

1

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.此时会出现一个确认对话框。

2

Confirm the collection to delete.确认要删除的集合。

In the dialog, enter the name of the collection to delete.在对话框中,输入要删除的集合的名称。

3

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 provides the following collection information and functionality in the detailed view:选择集合后,Compass会显示该集合的“文档”选项卡。Compass在详细视图中提供以下集合信息和功能:

Note

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:要打开新选项卡以查看集合详细信息,请执行以下操作:

1

Click the caret icon next to the database which contains the collection you wish to view.单击包含要查看的集合的数据库旁边的插入符号图标。

2

Hover over the desired collection.将鼠标悬停在所需集合上。

3

Click the appearing ellipses (...) button.单击出现的省略号(…)按钮。

4

Click Open in New Tab.单击“在新选项卡中打开”。

Limitations局限性

  • Creating and dropping collections is not permitted in MongoDB Compass Readonly Edition.“MongoDB Compass只读版本”中不允许创建和删除集合。
  • The Create Collection button is not available if you are connected to a Data Lake.如果连接到数据湖,则“创建集合”按钮不可用。