@@ -88,22 +88,26 @@ Aggregation Pipeline Changes
88
88
:pipeline:`$out`.
89
89
90
90
:pipeline:`$out` will create a new collection if one does not
91
- already exist in the current database. This collection will not be
92
- visible at that name until the aggregation completes. If the aggregation
93
- fails part-way through, no collection will be created.
94
-
95
- If the output collection already exists, the behavior is the same
96
- as MapReduce's replace mode. To be specific if the aggregation completes
97
- successfully, the output collection will be atomically replaced by a newer
98
- version. Any indexes that existed at the start of the aggregation on the
99
- original output collection will also exist on the new collection.
100
- Importantly, this means that the pipeline will error out if the output
101
- documents would violate any unique indexes (including _id) that existed
102
- on the original output collection.
91
+ already exist in the current database. This collection is not
92
+ visible until the aggregation completes. If the aggregation
93
+ fails, no collection MongoDB will not create any collection.
103
94
95
+ If the output collection already exists, when the aggregation
96
+ completes *successfully*, the :pipeline:`$out` atomically replaces
97
+ the output collection with the new results
98
+ collection. :pipeline:`$out` does not change any indexes that
99
+ existed on the previous collection.
100
+
101
+ .. important:: The pipeline will fail to complete if the documents
102
+ produced by the pipeline would violate any unique indexes,
103
+ including the index on the ``_id`` field, that existed on the
104
+ original output collection.
104
105
105
106
You may *only* specify :pipeline:`$out` at the end of a pipeline.
106
107
108
+ With :pipeline:`$out`, the aggregation framework can return result
109
+ sets of any size.
110
+
107
111
.. example::
108
112
109
113
The following operation will insert all documents in ``records``
@@ -116,8 +120,10 @@ Aggregation Pipeline Changes
116
120
db.records.aggregate( { $project: { uid: 1, email: 1 } },
117
121
{ $out: "users" } )
118
122
119
- With :pipeline:`$out`, the aggregation framework can return result
120
- sets of any size.
123
+ .. [#same-as-replace] When the :pipeline:`$out` operation specifies
124
+ a collection that already exists in the current database,
125
+ :pipeline:`$out` behaves like the replace mode of
126
+ :dbcommand:`mapReduce`.
121
127
122
128
Aggregation Operation May Return a Cursor
123
129
`````````````````````````````````````````
0 commit comments