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

mapReduce key comparisons do not respect the collation

    • Query
    • Fully Compatible
    • ALL

      The keys produced by the mapReduce emit function are always compared using the simple collation rather than the mapReduce operation's collation. For example, consider the following script:

      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.mapReduce(
          function() { emit(this.str, 1); },
          function(key, values) { return Array.sum(values); },
          {out: {inline: 1}, collation: {locale: "en", strength: 2}}
      );
      

      This script produces output such as the following:

      {
      	"results" : [
      		{
      			"_id" : "BAR",
      			"value" : 1
      		},
      		{
      			"_id" : "FOO",
      			"value" : 1
      		},
      		{
      			"_id" : "bar",
      			"value" : 1
      		},
      		{
      			"_id" : "foo",
      			"value" : 1
      		}
      	],
      	"timeMillis" : 133,
      	"counts" : {
      		"input" : 4,
      		"emit" : 4,
      		"reduce" : 0,
      		"output" : 4
      	},
      	"ok" : 1
      }
      

      Since the operation is using the English case-insensitive collation, one might expect the results array to contain 2 elements rather than 4. This is because "FOO" == "foo" and "BAR" == "bar" with respect to the collation.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: