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

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

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.3.11
    • Aggregation Framework
    • None
    • Fully Compatible
    • Query 18 (08/05/16)

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: