Views意见

Views are read-only results of an aggregation run against a collection. 视图是针对集合运行的聚合的只读结果。Views provide easy access to the results of an aggregation without requiring the reader of the view to execute the pipeline. 视图提供了对聚合结果的轻松访问,而无需视图的读取器执行管道。Views can also help keep your data secure by only giving users access to a predefined result set, as opposed to having access to the underlying collection.视图还可以通过只允许用户访问预定义的结果集而不是访问基础集合来帮助保持数据的安全。

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

Compass displays views in the Collections Screen with a special icon, and indicates the collection from which the view was created.Compass在“集合”屏幕中显示带有特殊图标的视图,并指示从中创建视图的集合。

View list

The Collections screen displays the following information for each view in the selected database:“集合”屏幕显示选定数据库中每个视图的以下信息:

  • View name视图名称
  • Collection from which the view was created从中创建视图的集合
  • Total size of all documents in the view视图中所有文档的总大小
  • Total size of all indexes on the collection集合上所有索引的总大小

To create a view, you must use the Aggregation Pipeline Builder. 要创建视图,必须使用聚合管道生成器The output of your pipeline's final stage becomes the content of the view.管道最后阶段的输出将成为视图的内容。

To create a view from your pipeline results:要根据管道结果创建视图,请执行以下操作:

  1. Create an aggregation pipeline in the pipeline builder. 在管道生成器中创建聚合管道。For detailed instructions on using the pipeline builder, see Create an Aggregation Pipeline.有关使用管道生成器的详细说明,请参阅创建聚合管道
  2. Click the arrow next to the Save button at the top of the pipeline builder.单击管道生成器顶部“保存”按钮旁边的箭头。
  3. Click Create a View.单击“创建视图”。
  4. Enter a name for your view.输入视图的名称。
  5. Click Create.单击“创建”。

Compass creates a view from your pipeline results in the same database where the pipeline was created.Compass根据管道结果在创建管道的同一数据库中创建视图。

To open a view, either:要打开视图,请执行以下任一操作:

  • Click the desired view from the Collections screen, or“集合”屏幕中单击所需视图,或
  • Click the desired view in the left-hand navigation.单击左侧导航中所需的视图。

After you open a view, Compass shows you that view's Documents Tab. 打开视图后,Compass将显示该视图的“文档”选项卡Compass provides the following information and functionality for the view:Compass为视图提供以下信息和功能:

You can duplicate a view to modify an existing view while retaining the original.可以复制视图以修改现有视图,同时保留原始视图。

To duplicate a view:要复制视图,请执行以下操作:

  1. Hover over the desired view in the left navigation.将鼠标悬停在左侧导航栏中所需的视图上。
  2. Click the appearing Ellipses (...) button.单击出现的省略号(…)按钮。
  3. In the dropdown, click Duplicate View.在下拉列表中,单击“复制视图”。
  4. Enter a name for the new view.输入新视图的名称。
  5. Click Duplicate.单击“复制”。
Note
Considerations考虑

Views are read-only, and cannot inherently be modified. 视图是只读的,不能进行修改。This procedure describes modifying the underlying source of a view.此过程描述如何修改视图的基础源

When you modify a view, Compass cannot retain collation information associated with the view. 修改视图时,Compass无法保留与该视图关联的排序规则信息。Any collation information must be re-entered in the pipeline builder during modification.修改期间,必须在管道生成器中重新输入任何排序规则信息。

To modify the source of a view:要修改视图的源,请执行以下操作:

  1. Click the desired view in the left navigation.单击左侧导航中所需的视图。
  2. At the top of the view, click Modify Source. 在视图顶部,单击“修改源”。This button opens the aggregation pipeline builder and populates the pipeline used to create the view.此按钮打开聚合管道生成器并填充用于创建视图的管道。
  3. Modify the pipeline as desired. For detailed instructions on using the pipeline builder, see Create an Aggregation Pipeline.根据需要修改管道。有关使用管道生成器的详细说明,请参阅创建聚合管道
  4. Click Update View at the top of the pipeline builder.单击管道生成器顶部的“更新视图”。

To drop a view from the database:要从数据库中删除视图:

  1. Hover over the desired view in the left navigation.将鼠标悬停在左侧导航栏中所需的视图上。
  2. Click the appearing Ellipses (...) button.单击出现的省略号(…)按钮。
  3. In the dropdown, click Drop View.在下拉列表中,单击“删除视图”。
  4. In the modal, enter the name of the view.在模式中,输入视图的名称。
  5. Click Drop Collection.单击“删除集合”。

Compass explicitly marks views in the left navigation with a unique icon:Compass使用唯一图标明确标记左侧导航中的视图:

View icon