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

Can't use subfields of composite _id in $group _id

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.2, 2.3.1
    • Affects Version/s: 2.2.0
    • Component/s: Aggregation Framework
    • None
    • Environment:
      Ubuntu 12.04, installed from 10gen ppa
    • ALL

      This works as expected:

      > db.b.insert({k:{a:2,b:1},v:567})
      > db.b.insert({k:{a:1,b:1},v:111})
      > db.b.insert({k:{a:1,b:2},v:12})
      > db.b.insert({k:{a:2,b:2},v:22})
      > db.b.aggregate({$group:{_id:'$k.a', s:{$sum:'$v'}}})
      {
              "result" : [
                      {
                              "_id" : 1,
                              "s" : 123
                      },
                      {
                              "_id" : 2,
                              "s" : 589
                      }
              ],
              "ok" : 1
      }
      

      But when using _id instead of k, it doesn't:

      > db.a.insert({_id:{a:1,b:1},v:123})
      > db.a.insert({_id:{a:1,b:2},v:345})
      > db.a.insert({_id:{a:2,b:2},v:222})
      > db.a.insert({_id:{a:2,b:1},v:567})
      > db.a.aggregate({$group:{_id:'$_id.a', s:{$sum:'$v'}}})
      { "result" : [ { "_id" : null, "s" : 1257 } ], "ok" : 1 }
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            maciej.gajewski Maciej Gajewski
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: