@@ -45,7 +45,6 @@ The :pipeline:`$out` stage has the following syntax:
45
45
- Description
46
46
47
47
* - :ref:`db <out-db>`
48
-
49
48
- .. _out-db:
50
49
51
50
The output database name.
@@ -58,7 +57,6 @@ The :pipeline:`$out` stage has the following syntax:
58
57
output database must already exist.
59
58
60
59
* - :ref:`coll <out-collection>`
61
-
62
60
- .. _out-collection:
63
61
64
62
The output collection name.
@@ -76,77 +74,60 @@ The :pipeline:`$out` stage has the following syntax:
76
74
collection. The input collection for a pipeline can be sharded.
77
75
To output to a sharded collection, see :pipeline:`$merge`
78
76
(Available starting in MongoDB 4.2).
79
-
80
77
- The :pipeline:`$out` operator cannot write results to a
81
78
: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
+
82
83
83
84
.. _out-merge-comparison:
84
85
85
86
Comparison with ``$merge``
86
87
~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88
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:
148
93
94
+ .. list-table::
95
+ :header-rows: 1
149
96
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
150
131
151
132
Behaviors
152
133
---------
@@ -203,6 +184,10 @@ The pipeline will fail to complete if the documents produced by the
203
184
pipeline would violate any unique indexes, including the index on the
204
185
``_id`` field of the original output collection.
205
186
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
+
206
191
``majority`` Read Concern
207
192
~~~~~~~~~~~~~~~~~~~~~~~~~
208
193
0 commit comments