Skip to content

Commit 0604296

Browse files
committed
Changed $addFields for $set to conform with the Aggregation Skill Badge Training
1 parent a5f16a9 commit 0604296

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

docs/80-modifying-results/adding-fields.mdx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import TabItem from '@theme/TabItem';
77

88
# 👐 Adding New Fields to Results
99

10-
## $addFields
10+
## $set / $addFields
1111

12-
We want to estimate the reading time for a book. But we don't have that field stored in our data. We can use `$addFields` for this. If the field exists, it'll get updated, and if it doesn't, it's added.
12+
We want to estimate the reading time for a book. But we don't have that field stored in our data. We can use `$set` for this. If the field exists, it'll get updated, and if it doesn't, it's added.
1313

1414

1515
<Tabs groupId="aggregations">
@@ -22,7 +22,7 @@ We want to estimate the reading time for a book. But we don't have that field st
2222
pages: 1,
2323
}
2424
},
25-
{$addFields: {readingTimeHours: {$divide: [{$multiply: ["$pages", 2]}, 60]}}},
25+
{$set: {readingTimeHours: {$divide: [{$multiply: ["$pages", 2]}, 60]}}},
2626
]
2727
```
2828

@@ -37,7 +37,7 @@ db.books.aggregate([
3737
pages: 1,
3838
}
3939
},
40-
{$addFields: {readingTimeHours: {$divide: [{$multiply: ["$pages", 2]}, 60]}}},
40+
{$set: {readingTimeHours: {$divide: [{$multiply: ["$pages", 2]}, 60]}}},
4141
])
4242
```
4343

@@ -62,7 +62,7 @@ db.books.aggregate([
6262
pages: 1,
6363
}
6464
},
65-
{$addFields: {notes: "PLACEHOLDER"}}
65+
{$set: {notes: "PLACEHOLDER"}}
6666
]
6767
```
6868

@@ -78,19 +78,16 @@ db.books.aggregate([
7878
pages: 1,
7979
}
8080
},
81-
{$addFields: {notes: "PLACEHOLDER"}}
81+
{$set: {notes: "PLACEHOLDER"}}
8282
])
8383
```
8484

8585
</TabItem>
8686
</Tabs>
8787

88-
89-
9088
</div>
89+
</details>
9190

9291
:::info
93-
[$set](https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set) is an alias for $addFields that you'll find on many older posts and documentation.
94-
:::
95-
96-
</details>
92+
[$set](https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set) is a new alias for `$addFields`. You'll still find `$addFields` on many older posts and documentation.
93+
:::

docs/80-modifying-results/unset-fields.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_position: 20
55
import Tabs from '@theme/Tabs';
66
import TabItem from '@theme/TabItem';
77

8-
# 👐 Unset Fields from Results
8+
# 👐 Removing Fields from Results
99

1010
## $unset
1111

0 commit comments

Comments
 (0)