Skip to content

Commit 44e5d33

Browse files
authored
(DOCSP-32324) Adds info on how to create a view in the Atlas UI (#4872) (#4967)
* (DOCSP-32324) Adds info on how to create a view in the Atlas UI * Moves content to the Materialized View page * Includes copy review changes * Includes copy review change
1 parent 5294889 commit 44e5d33

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

source/core/materialized-views.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ On-Demand Materialized Views
44

55
.. default-domain:: mongodb
66

7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
713
.. meta::
814
:description: MongoDB on-demand materialized view
915
:keywords: MongoDB, materialized view
@@ -20,6 +26,86 @@ of completely replacing the collection. This functionality allows users
2026
to create on-demand materialized views, where the content of the output
2127
collection can be updated each time the pipeline is run.
2228

29+
30+
.. _create-view-atlas:
31+
32+
Create a Materialized View in the {+atlas+} UI
33+
-------------------------------------------------------
34+
35+
The example in this section uses the :atlas:`sample movies dataset
36+
</sample-data/sample-mflix/>`. To learn how to load the sample dataset
37+
into your {+atlas+} deployment, see :atlas:`Load Sample Data
38+
</sample-data/#std-label-load-sample-data>`.
39+
40+
To create a materialized view in the {+atlas+} UI, follow these
41+
steps:
42+
43+
.. procedure::
44+
:style: normal
45+
46+
.. step:: Navigate to the collection
47+
48+
a. In the {+atlas+} UI, click :guilabel:`Database` in the sidebar.
49+
#. For the database deployment that contains the sample data,
50+
click :guilabel:`Browse Collections`.
51+
#. In the left navigation pane, select the
52+
:guilabel:`sample_training` database.
53+
#. Select the :guilabel:`grades` collection.
54+
55+
.. step:: Click the :guilabel:`Aggregation` tab
56+
57+
.. step:: Click :guilabel:`Add Stage`
58+
59+
.. step:: Select an aggregation stage from the :guilabel:`Select` drop-down menu
60+
61+
The aggregation stage transforms the data that you want to save as
62+
a view. To learn more about available aggregation stages, see
63+
:ref:`agg-pipeline-quick-ref`.
64+
65+
For this example, add a new field with the :pipeline:`$set` stage:
66+
67+
a. Select :pipeline:`$set` from the :guilabel:`Select` drop-down
68+
menu.
69+
#. Add the following syntax to the aggregation pipeline
70+
editor to create an average score across all ``score``
71+
values in the ``scores`` array within the ``grades``
72+
collection:
73+
74+
.. code-block::
75+
76+
{
77+
averageScore: { $avg: "$scores.score" }
78+
}
79+
80+
{+atlas+} adds the ``averageScore`` value to each document.
81+
82+
.. step:: Click :guilabel:`Add Stage`
83+
84+
.. step:: Add the ``$out`` stage
85+
86+
a. Select the :pipeline:`$out` stage from the :guilabel:`Select`
87+
drop-down menu.
88+
#. Add the following syntax to the aggregation pipeline
89+
to write the results of the pipeline to the ``myView``
90+
collection in the ``sample_training`` database:
91+
92+
.. code-block::
93+
94+
'myView'
95+
96+
#. Click :guilabel:`Save Documents`.
97+
98+
The :pipeline:`$out` stage writes the results of the
99+
aggregation pipeline to the specified collection, which creates
100+
the view. To learn more, see :pipeline:`$out`.
101+
102+
Refresh the list of collections to see the ``myView`` collection.
103+
104+
To learn how to query the ``myView`` collection in the {+atlas+}
105+
UI, see :atlas:`View, Filter, and Sort Documents
106+
</atlas-ui/documents/#view--filter--and-sort-documents>` in the
107+
{+atlas+} documentation.
108+
23109
Example
24110
-------
25111

source/core/views.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ For example, you can:
3636
query the joined data without managing or understanding the underlying
3737
complex pipeline.
3838

39+
.. |page-topic| replace:: create views
40+
.. |link-topic-ing| replace:: creating materialized views in the UI
41+
.. |atlas-url| replace:: :ref:`create-view-atlas`
42+
43+
.. include:: /includes/fact-atlas-compatible.rst
44+
.. include:: /includes/fact-atlas-link.rst
45+
3946
When clients :ref:`query a view <views-supported-operations>`, MongoDB
4047
appends the client query to the underlying pipeline and returns the
4148
results of that combined pipeline to the client. MongoDB may apply

source/meta/aggregation-quick-reference.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
with slight difference. Quick Reference contains information on different expressions,
44
such as field paths, expression objects, etc.
55

6+
.. _agg-pipeline-quick-ref:
7+
68
====================================
79
Aggregation Pipeline Quick Reference
810
====================================

0 commit comments

Comments
 (0)