[DOCS-8911] No way to $project out just the _id field in aggregation Created: 28/Sep/16  Updated: 11/Jan/17  Resolved: 18/Nov/16

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Unassigned
Resolution: Duplicate 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
Duplicate
duplicates DOCS-8973 Allow exclusion in $project stage of ... Closed
Participants:
Days since reply: 7 years, 20 weeks ago
Epic Link: 3.4 Agg/Arrays

 Description   

The command

db.example.aggregate([{$project: {_id: 0}}])

fails because "$project requires at least one output field." Now that $project supports exclusion of other fields, it would be nice if it supports exclusion of just the _id field.

Interestingly, I can enforce "exclusion mode" by projecting out a field that doesn't exist:

> db.example.find()
{ "_id" : ObjectId("576d9dc03fcfa43a8b713c74"), "a" : { "a1" : 5, "a2" : 6 }}
{ "_id" : ObjectId("57716feaf6545b026b3dfca1"), "a" : { "a1" : 3, "a2" : 7 }}
> db.example.aggregate([{$project: {_id: 0, c: 0} }])
{"a" : {"a1":5, "a2":6 } , "b":4 }
{"a" : {"a1":3, "a2":7 }}


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