sidebar_position |
---|
20 |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
We can remove fields from the results, either using $project or more fine-grained, using $unset. If we don't want the attributes, we can do:
[
{$unset: "attributes"}
]
db.books.aggregate([
{$unset: "attributes"}
])
👐 Remove from results the fields totalInventory
and available
.
Answer
Several ways to do this, other than using $project
:
[
{$unset: "totalInventory"},
{$unset: "available"},
]
// or
[
{$unset: ["totalInventory", "available"] },
]
db.books.aggregate([
{$unset: "totalInventory"},
{$unset: "available"},
])
// or
db.books.aggregate([
{$unset: ["totalInventory", "available"] },
])
:::info $set is an alias for $addFields that you'll find on many older posts and documentation. :::