Skip to main content

πŸ‘ 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"}
]

πŸ‘ 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"] },
]
info

$set is an alias for $addFields that you'll find on many older posts and documentation.