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

Improve error message when using $count with _id key

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible

      Running $count using _id as key returns the following error:

      test> db.foo.aggregate([{$count: "_id"}])
      MongoServerError[Location15948]: a group's _id may only be specified once
      

      This is because {$count: X} is just sugar for

      { $group: { _id: null, X: { $sum: 1 } } },
      { $project: {_id: 0}}
      

      Error is confusing and could be improved

            Assignee:
            sopho.kevlishvili@mongodb.com Sopho Kevlishvili (Inactive)
            Reporter:
            renato.riccio@mongodb.com Renato Riccio
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: