Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
Minor Change
-
Query 11 (03/14/16), Query 12 (04/04/16), Query 13 (04/22/16), Query 14 (05/13/16), Query 15 (06/03/16), Query 16 (06/24/16)
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}]}
|
Attachments
Issue Links
- duplicates
-
SERVER-22787 Add $lookup.excludeLocalField to exclude local field from output
-
- Backlog
-
- is depended on by
-
SERVER-22436 Allow parsing of string literals in aggregation's $project
-
- Closed
-
- is documented by
-
DOCS-8973 Allow exclusion in $project stage of aggregation pipeline
-
- Closed
-
- is duplicated by
-
SERVER-23411 Inconsistent results when setting a nested field in $project
-
- Closed
-
-
SERVER-22436 Allow parsing of string literals in aggregation's $project
-
- Closed
-
- is related to
-
SERVER-30633 Large performance regression for large aggregation queries
-
- Closed
-
-
DRIVERS-297 Aggregation Framework Support for 3.4
-
- Closed
-
-
SERVER-24921 No way to $project out just the _id field in aggregation
-
- Closed
-
- related to
-
SERVER-6714 Array in input doc schema incorrectly affects $project output
-
- Closed
-
-
SERVER-23411 Inconsistent results when setting a nested field in $project
-
- Closed
-
-
CSHARP-1598 allow exclusion in $project stage
-
- Closed
-
-
JAVA-2148 Ensure proper builder support for exclusions in the $project stage of an aggregation pipeline
-
- Closed
-
-
SERVER-5781 Implement $addFields aggregation stage for using expression language to add new fields to a document
-
- Closed
-