@@ -9,7 +9,7 @@ On-Demand Materialized Views
9
9
.. contents:: On this page
10
10
:local:
11
11
:backlinks: none
12
- :depth: 2
12
+ :depth: 1
13
13
:class: singlecol
14
14
15
15
.. meta::
@@ -36,6 +36,86 @@ Comparison with Standard Views
36
36
37
37
.. include:: /includes/views/fact-compare-view-and-materialized-view.rst
38
38
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
+
39
119
Example
40
120
-------
41
121
0 commit comments