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

Improve the error message if $last operator is used in _id field for $group operation

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Query

      If $last operator is used in _id field for $group operation, for example:

      db.test.aggregate([
          { $sort : { score : 1 }},
          { $group : {
                     _id : { name : "$name",
                             highest : { $last : "$score" }}}
          }
      ])
      

      the following error message is displayed:

      {
      	"errmsg" : "exception: invalid operator '$last'",
      	"code" : 15999,
      	"ok" : 0
      }
      

      The error message is not so helpful for the user to fix the issue. It would help if we had a more specific error message, i.e. not to use $last in the _id field.

      Similarly for $first operator.

      BTW, the correct usage should be:

      db.test.aggregate([
          { $sort : { score : 1 }},
          { $group : {
                     _id : { name : "$name" },
                     highest : { $last : "$score" }}
          }
      ])
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            linda.qin@mongodb.com Linda Qin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: