Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24921

No way to $project out just the _id field in aggregation

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.11
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • Query 18 (08/05/16)

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

            Assignee:
            sally.mcnichols Sally McNichols
            Reporter:
            carly.robison Carly Robison
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: