Skip to content

Commit c24f97d

Browse files
authored
Merge pull request #63 from Meg528/patch-48
Update saving-to-collection.mdx
2 parents 24afca2 + 796c9e2 commit c24f97d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

docs/90-exporting-data/saving-to-collection.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can export the result of an aggregation pipeline to a different DB/collectio
1010
<Tabs groupId="aggregations">
1111
<TabItem value="atlas" label="Atlas UI">
1212

13-
Run this from the source collection
13+
Run this from the source collection:
1414

1515
```js
1616
[{ $out: { db: "<output-db>", coll: "<output-collection>" } }]
@@ -93,19 +93,19 @@ Reference: [📗 `$out` documentation](https://www.mongodb.com/docs/manual/refer
9393

9494
If the collection specified by the `$out` operation already exists, then the `$out` stage atomically replaces the existing collection with the new results collection upon completion of the aggregation.
9595

96-
To avoid overwriting the existing collection we can use `$merge` instead of `$out`.
96+
To avoid overwriting the existing collection, we can use `$merge` instead of `$out`.
9797

9898
```
9999
{ $merge : { into : "newCollection" } }
100100
```
101101

102-
- if the collection does not exists, it will be created
103-
- if it exists, new data will be added
104-
- if [a doc already exists](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#std-label-merge-whenMatched), we can replace it, keep the existing one, merge both documents cause the stage to fail or run a pipeline.
102+
- If the collection does not exist, it will be created.
103+
- If it exists, new data will be added.
104+
- If [a doc already exists](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#std-label-merge-whenMatched), we can replace it, keep the existing one, merge both documents, and cause the stage to fail or run a pipeline.
105105

106-
This is perfect for creating [On-Demand Materialized Views](https://www.mongodb.com/docs/manual/core/materialized-views/)
106+
This is perfect for creating [on-demand materialized views](https://www.mongodb.com/docs/manual/core/materialized-views/)
107107

108-
As an example, let's say we want the authors to contain all the books they've written, with all the book information. In this case, we'll do a `$lookup` to get the book information into the authors collection. We can even use the name `books` for the resulting data we're joining, shadowing the original `books` array we have in authors. This way it will look like the `books` array changes.
108+
As an example, let's say we want the authors to contain all the books they've written, with all the book information. In this case, we'll do a `$lookup` to get the book information into the authors collection. We can even use the name `books` for the resulting data we're joining, shadowing the original `books` array we have in authors. This way, it will look like the `books` array changes.
109109

110110
```js
111111
[
@@ -119,7 +119,7 @@ As an example, let's say we want the authors to contain all the books they've wr
119119
]
120120
```
121121

122-
Now a book will look like this. You can see that the books array has been "overwritten" by the `$lookup`.
122+
Now, a book will look like this. You can see that the books array has been "overwritten" by the `$lookup`.
123123

124124
```js
125125
{
@@ -249,7 +249,7 @@ We can go ahead and remove the authors from the books array, as it is redundant:
249249
]
250250
```
251251

252-
Now that our authors look the way we want, we can overwrite the authors collection using `$merge`
252+
Now that our authors look the way we want, we can overwrite the authors collection using `$merge`.
253253

254254
```js
255255
[
@@ -269,9 +269,9 @@ Now that our authors look the way we want, we can overwrite the authors collecti
269269
]
270270
```
271271

272-
- we use the `_id` field to match documents
273-
- we replace the existing ones with `replace`
272+
- We use the `_id` field to match documents.
273+
- We replace the existing ones with `replace`.
274274

275275
:::warning
276276
We should see a message telling us that the $merge operator will cause the pipeline to persist the results to the specified location. This stage changes data.
277-
:::
277+
:::

0 commit comments

Comments
 (0)