Docs Menu

Docs HomeView & Analyze DataMongoDB Compass

Views

On this page

  • Collections Screen
  • Create a View
  • Open a View
  • Duplicate a View
  • Modify the Source of a View
  • Drop a View

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
click to enlarge

Compass displays views in the Collections Screen with a special icon, and indicates the collection from which the view was created.

View list
click to enlarge

The Collections screen displays the following information for each view in the selected database:

  • View name

  • Collection from which the view was created

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.

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 provides the following information and functionality for the view:

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 drop-down menu, 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. Any collation information must be re-entered in the pipeline builder during modification.

To modify the source of a view:

  1. Hover over the desired view in the left navigation.

  2. Click the appearing Ellipses (...) button.

  3. In the dropdown, click Modify view. This button opens the aggregation pipeline builder and populates the pipeline used to create the view.

  4. Modify the pipeline as desired. For detailed instructions on using the pipeline builder, see Create an Aggregation Pipeline.

  5. 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.

←  Create a Time Series CollectionManage Documents →