[SERVER-26422] Group command does not group with respect to the collation Created: 30/Sep/16  Updated: 06/Dec/22  Resolved: 07/Apr/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.3.15
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: David Storch Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-26426 mapReduce key comparisons do not resp... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

If the group key is a string, the group command should put all documents whose strings compare equal under the collation into the same group. However, the groups are instead determined using a simple binary string comparison. This can be reproduced as follows:

db.c.drop();
db.c.insert({_id: 1, str: "foo"});
db.c.insert({_id: 2, str: "FOO"});
db.c.insert({_id: 3, str: "bar"});
db.c.insert({_id: 4, str: "BAR"});
 
db.c.group({
    key: {str: 1},
    initial: {count: 0},
    reduce: function(curr, result) { result.count += 1; },
    collation: {locale: "en", strength: 2}
});

I would expect this to return 2 groups under the English case-insensitive collation, but instead the server returns 4.



 Comments   
Comment by David Storch [ 07/Apr/17 ]

Closing as Won't Fix due to the group command deprecation, as Asya suggested.

Comment by Asya Kamsky [ 28/Mar/17 ]

Since group command has been deprecated, recommend closing this as won't fix.

Comment by David Storch [ 30/Sep/16 ]

This is specific to the group command. Aggregation's $group is not affected. All we need to do to fix is make GroupStage::_groupMap use a BSONObjComparator with the proper collator. Right now we initialize _groupMap with the SimpleBSONObjComparator:

https://github.com/mongodb/mongo/blob/r3.3.15/src/mongo/db/exec/group.cpp#L90

Generated at Thu Feb 08 04:12:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.