@@ -9,7 +9,7 @@ On-Demand Materialized Views
99.. contents:: On this page
1010 :local:
1111 :backlinks: none
12- :depth: 2
12+ :depth: 1
1313 :class: singlecol
1414
1515.. meta::
@@ -36,6 +36,86 @@ Comparison with Standard Views
3636
3737.. include:: /includes/views/fact-compare-view-and-materialized-view.rst
3838
39+
40+ .. _create-view-atlas:
41+
42+ Create a Materialized View in the {+atlas+} UI
43+ -------------------------------------------------------
44+
45+ The example in this section uses the :atlas:`sample movies dataset
46+ </sample-data/sample-mflix/>`. To learn how to load the sample dataset
47+ into your {+atlas+} deployment, see :atlas:`Load Sample Data
48+ </sample-data/#std-label-load-sample-data>`.
49+
50+ To create a materialized view in the {+atlas+} UI, follow these
51+ steps:
52+
53+ .. procedure::
54+ :style: normal
55+
56+ .. step:: Navigate to the collection
57+
58+ a. In the {+atlas+} UI, click :guilabel:`Database` in the sidebar.
59+ #. For the database deployment that contains the sample data,
60+ click :guilabel:`Browse Collections`.
61+ #. In the left navigation pane, select the
62+ :guilabel:`sample_training` database.
63+ #. Select the :guilabel:`grades` collection.
64+
65+ .. step:: Click the :guilabel:`Aggregation` tab
66+
67+ .. step:: Click :guilabel:`Add Stage`
68+
69+ .. step:: Select an aggregation stage from the :guilabel:`Select` drop-down menu
70+
71+ The aggregation stage transforms the data that you want to save as
72+ a view. To learn more about available aggregation stages, see
73+ :ref:`agg-pipeline-quick-ref`.
74+
75+ For this example, add a new field with the :pipeline:`$set` stage:
76+
77+ a. Select :pipeline:`$set` from the :guilabel:`Select` drop-down
78+ menu.
79+ #. Add the following syntax to the aggregation pipeline
80+ editor to create an average score across all ``score``
81+ values in the ``scores`` array within the ``grades``
82+ collection:
83+
84+ .. code-block::
85+
86+ {
87+ averageScore: { $avg: "$scores.score" }
88+ }
89+
90+ {+atlas+} adds the ``averageScore`` value to each document.
91+
92+ .. step:: Click :guilabel:`Add Stage`
93+
94+ .. step:: Add the ``$out`` stage
95+
96+ a. Select the :pipeline:`$out` stage from the :guilabel:`Select`
97+ drop-down menu.
98+ #. Add the following syntax to the aggregation pipeline
99+ to write the results of the pipeline to the ``myView``
100+ collection in the ``sample_training`` database:
101+
102+ .. code-block::
103+
104+ 'myView'
105+
106+ #. Click :guilabel:`Save Documents`.
107+
108+ The :pipeline:`$out` stage writes the results of the
109+ aggregation pipeline to the specified collection, which creates
110+ the view. To learn more, see :pipeline:`$out`.
111+
112+ Refresh the list of collections to see the ``myView`` collection.
113+
114+ To learn how to query the ``myView`` collection in the {+atlas+}
115+ UI, see :atlas:`View, Filter, and Sort Documents
116+ </atlas-ui/documents/#view--filter--and-sort-documents>` in the
117+ {+atlas+} documentation.
118+
39119Example
40120-------
41121
0 commit comments