[SERVER-24921] No way to $project out just the _id field in aggregation Created: 06/Jul/16  Updated: 03/May/17  Resolved: 04/Aug/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.3.11

Type: New Feature Priority: Major - P3
Reporter: Carly Robison Assignee: Sally McNichols
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-8911 No way to $project out just the _id f... Closed
is documented by DOCS-8973 Allow exclusion in $project stage of ... Closed
Related
related to SERVER-18966 Allow exclusion in $project stage of ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 18 (08/05/16)
Participants:

 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 }}



 Comments   
Comment by Githook User [ 04/Aug/16 ]

Author:

{u'username': u'smcnichols', u'name': u'Sally McNichols', u'email': u'sally.mcnichols@mongodb.com'}

Message: SERVER-24921 allow excluding only the _id field in $project
Branch: master
https://github.com/mongodb/mongo/commit/1f291f5be44a18bd578b9a2402715531ed5d0a67

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