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集合存在于单个数据库

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

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

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

1

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

2

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.如果要对集合使用自定义排序规则,请选中“使用自定义排序规则”复选框,然后选择所需的排序规则设置。

3
1

From the Collections screen, click on the trash can for the collection to delete. 在“集合”屏幕中,单击要删除的集合的垃圾桶。A confirmation dialog appears.此时会出现一个确认对话框。

2

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

3

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.在新选项卡中打开集合。
Select a collection

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在详细视图中提供以下集合信息和功能:

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为您的架构设置验证规则

You can open multiple Collection Detail screens in separate tabs. 您可以在单独的选项卡中打开多个集合详细信息屏幕。To open a new tab to view collection details:要打开新选项卡以查看集合详细信息,请执行以下操作:

1
Image highlighting database caret button
2
3
4
  • 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.如果连接到数据湖,“创建集合”按钮不可用。
←  DatabasesViews →