Skip to content

Latest commit

 

History

History
91 lines (60 loc) · 1.38 KB

File metadata and controls

91 lines (60 loc) · 1.38 KB
sidebar_position
20

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

👐 Unset Fields From Results

$unset

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. :::