[DOCS-8973] Allow exclusion in $project stage of aggregation pipeline Created: 28/Sep/16  Updated: 03/May/17  Resolved: 17/Jan/17

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: 3.4.0

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Allison Reinheimer Moore
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-24921 No way to $project out just the _id f... Closed
documents SERVER-18966 Allow exclusion in $project stage of ... Closed
Duplicate
is duplicated by DOCS-8911 No way to $project out just the _id f... Closed
Participants:
Days since reply: 7 years, 4 weeks, 1 day ago
Epic Link: 3.4 Agg/Arrays
Story Points: 0.5

 Description   

There is currently no way to easily specify that project stage keep all fields except for a particular one (with exception of _id).

This can be helpful to limit the amount of data returned when some aggregation also needs to be done.

Examples

// Exclude a single field.
> db.example.insert([
  {_id: 0, a: 1}
]);
> db.example.aggregate([{$project: {a: 0}}])
{_id: 0}
> db.example.aggregate([{$project: {a: false}}])  // Means the same thing as above.
{_id: 0}
 
// Exclude a nested field.
> db.example.drop()
> db.example.insert([
  {_id: 0, a: {b: 1, c: 1}}
]);
> db.example.aggregate([{$project: {'a.b': 0}}])
{_id: 0, a: {c: 1}}
> db.example.aggregate([{$project: {a: {b: 0}}}])  // Means the same thing as above.
{_id: 0, a: {c: 1}}
 
// Exclude a nested field from an array.
> db.example.drop()
> db.example.insert([
  {_id: 0, a: [{b: 1, c: 1}, {b: 2, c: 2}]}
]);
> db.example.aggregate([{$project: {'a.b': 0}}])
{_id: 0, a: [{c: 1}, {c: 2}]}
> db.example.aggregate([{$project: {a: {b: 0}}}])  // Means the same thing as above.
{_id: 0, a: [{c: 1}, {c: 2}]}



 Comments   
Comment by Githook User [ 18/Jan/17 ]

Author:

{u'username': u'schmalliso', u'name': u'Allison Moore', u'email': u'allison.moore@10gen.com'}

Message: DOCS-8973: exclude fields in $project

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/a980e90754365dbd956acd836e1dadd7c0546a8d

Generated at Thu Feb 08 07:57:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.