[SERVER-7491] Can't use subfields of composite _id in $group _id Created: 27/Oct/12 Updated: 11/Jul/16 Resolved: 05/Nov/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 2.2.0 |
| Fix Version/s: | 2.2.2, 2.3.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Maciej Gajewski | Assignee: | Mathias Stearn |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu 12.04, installed from 10gen ppa |
||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
This works as expected:
But when using _id instead of k, it doesn't:
|
| Comments |
| Comment by auto [ 06/Nov/12 ] | ||||||||||||||||||||
|
Author: {u'date': u'2012-10-29T18:33:34Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}Message: This requires special casing due to | ||||||||||||||||||||
| Comment by auto [ 05/Nov/12 ] | ||||||||||||||||||||
|
Author: {u'date': u'2012-10-29T18:33:34Z', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}Message: This requires special casing due to | ||||||||||||||||||||
| Comment by Mathias Stearn [ 29/Oct/12 ] | ||||||||||||||||||||
|
I see the issue. You can work around it by explicitly including _id in a $project before the $group or using the full _id in the $group.
The issue is that we don't fetch the _id from the database is it isn't being used. I think the logic ignored the subfield of _id case. BTW, unrelated to this issue, but it is often a bad idea to use a multi-field key as the _id. Not all drivers maintain order of fields and {a:1, b:1}!= {b:1, a:1}in mongodb so you have to be very careful that you don't end up with duplicate documents. Note that single key objects don't have this issue, so {_id: {color:'red'}} is ok. |