Skip to content

Commit 65726f2

Browse files
author
Dave
authored
DOCS-15052 BACKPORT (#420)
1 parent d64d6dd commit 65726f2

File tree

1 file changed

+48
-63
lines changed
  • source/reference/operator/aggregation

1 file changed

+48
-63
lines changed

source/reference/operator/aggregation/out.txt

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ The :pipeline:`$out` stage has the following syntax:
4545
- Description
4646

4747
* - :ref:`db <out-db>`
48-
4948
- .. _out-db:
5049

5150
The output database name.
@@ -58,7 +57,6 @@ The :pipeline:`$out` stage has the following syntax:
5857
output database must already exist.
5958

6059
* - :ref:`coll <out-collection>`
61-
6260
- .. _out-collection:
6361

6462
The output collection name.
@@ -76,77 +74,60 @@ The :pipeline:`$out` stage has the following syntax:
7674
collection. The input collection for a pipeline can be sharded.
7775
To output to a sharded collection, see :pipeline:`$merge`
7876
(Available starting in MongoDB 4.2).
79-
8077
- The :pipeline:`$out` operator cannot write results to a
8178
:doc:`capped collection </core/capped-collections>`.
79+
- If you modify a collection with an :atlas:`Atlas Search
80+
</atlas-search>` index, you must first delete and then re-create
81+
the search index. Consider using :pipeline:`$merge` instead.
82+
8283

8384
.. _out-merge-comparison:
8485

8586
Comparison with ``$merge``
8687
~~~~~~~~~~~~~~~~~~~~~~~~~~
8788

88-
.. note:: ``$merge`` and ``$out`` Comparison
89-
90-
With the introduction of :pipeline:`$merge` in version 4.2, MongoDB
91-
provides two stages, :pipeline:`$merge` and :pipeline:`$out`, for
92-
writing the results of the aggregation pipeline to a collection. The
93-
following summarizes the capabilities of the two stages:
94-
95-
.. list-table::
96-
:header-rows: 1
97-
:class: border-table
98-
99-
* - :pipeline:`$out`
100-
- :pipeline:`$merge`
101-
102-
* - - Available starting in MongoDB 2.6
103-
- - Available starting in MongoDB 4.2
104-
105-
* - - Can output to a collection in the same or, starting in
106-
MongoDB 4.4, different database.
107-
108-
- - Can output to a collection in the same or different database.
109-
110-
111-
* - - Creates a new collection if the output collection does not
112-
already exist.
113-
- - Creates a new collection if the output collection does not
114-
already exist.
115-
116-
* - - Replaces the output collection completely if it already exists.
117-
118-
- - Can incorporate results (insert new documents, merge
119-
documents, replace documents, keep existing documents, fail
120-
the operation, process documents with a custom update pipeline) into
121-
an existing collection.
122-
123-
Can replace the content of the collection but only if the
124-
aggregation results contain a match for all existing
125-
documents in the collection.
126-
127-
* - - Cannot output to a sharded collection. Input collection,
128-
however, can be sharded.
129-
130-
- - Can output to a sharded collection. Input collection can
131-
also be sharded.
132-
133-
* - - Corresponds to SQL statements:
134-
135-
- ``INSERT INTO T2 SELECT FROM T1``.
136-
137-
- ``SELECT INTO T2 FROM T1``.
138-
139-
- - Corresponds to SQL statements:
140-
141-
- ``MERGE``.
142-
143-
- ``INSERT INTO T2 SELECT FROM T1``.
144-
145-
- ``SELECT INTO T2 FROM T1``.
146-
147-
- Create/Refresh Materialized Views.
89+
With the introduction of :pipeline:`$merge` in version 4.2, MongoDB
90+
provides two stages, :pipeline:`$merge` and :pipeline:`$out`, for
91+
writing the results of the aggregation pipeline to a collection. The
92+
following summarizes the capabilities of the two stages:
14893

94+
.. list-table::
95+
:header-rows: 1
14996

97+
* - :pipeline:`$out`
98+
- :pipeline:`$merge`
99+
* - - Available starting in MongoDB 2.6
100+
- - Available starting in MongoDB 4.2
101+
* - - Can output to a collection in the same or, starting in
102+
MongoDB 4.4, different database.
103+
- - Can output to a collection in the same or different database.
104+
* - - Creates a new collection if the output collection does not
105+
already exist.
106+
- - Creates a new collection if the output collection does not
107+
already exist.
108+
* - - Replaces the output collection completely if it already exists.
109+
- - Can incorporate results (insert new documents, merge
110+
documents, replace documents, keep existing documents, fail
111+
the operation, process documents with a custom update pipeline) into
112+
an existing collection.
113+
114+
Can replace the content of the collection but only if the
115+
aggregation results contain a match for all existing
116+
documents in the collection.
117+
* - - Cannot output to a sharded collection. Input collection,
118+
however, can be sharded.
119+
- - Can output to a sharded collection. Input collection can
120+
also be sharded.
121+
* - - Corresponds to SQL statements:
122+
123+
- ``INSERT INTO T2 SELECT FROM T1``
124+
- ``SELECT INTO T2 FROM T1``
125+
- - Corresponds to SQL statements:
126+
127+
- ``MERGE``
128+
- ``INSERT INTO T2 SELECT FROM T1``
129+
- ``SELECT INTO T2 FROM T1``
130+
- Create/Refresh Materialized Views
150131

151132
Behaviors
152133
---------
@@ -203,6 +184,10 @@ The pipeline will fail to complete if the documents produced by the
203184
pipeline would violate any unique indexes, including the index on the
204185
``_id`` field of the original output collection.
205186

187+
If the :pipeline:`$out` operation modifies a collection with an
188+
:atlas:`Atlas Search </atlas-search>` index, you must delete and
189+
re-create the search index. Consider using :pipeline:`$merge` instead.
190+
206191
``majority`` Read Concern
207192
~~~~~~~~~~~~~~~~~~~~~~~~~
208193

0 commit comments

Comments
 (0)