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

Unique 2dsphere multikey indexes behave differently than non-2dsphere counterparts

    • Query Integration
    • ALL
    • Hide
      python buildscripts/resmoke.py unique_2dsphere_multikey_index.js
      
      unique_2dsphere_multikey_index.js
      (function() {
          "use strict";
      
          assert.writeOK(db.mycoll.insert({x: [{a: 1, b: 1}, {a: 2, b: 2}], geo: [0, 0]}));
          assert.writeOK(db.mycoll.insert({x: [{a: 1, b: 2}, {a: 2, b: 1}], geo: [0, 0]}));
      
          assert.commandWorked(db.mycoll.createIndex({"x.a": 1, "x.b": 1}, {unique: true}));
          assert.commandWorked(
              db.mycoll.createIndex({"x.a": 1, "x.b": 1, geo: "2dsphere"}, {unique: true}));
      })();
      
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 2017-09-28T20:37:37.937-0400 E QUERY    [thread1] Error: command failed: {
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 	"ok" : 0,
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 	"errmsg" : "E11000 duplicate key error collection: test.mycoll index: x.a_1_x.b_1_geo_2dsphere dup key: { : 1.0, : 1.0, : 1152921504606846977 }",
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 	"code" : 11000,
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 	"codeName" : "DuplicateKey"
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 } : undefined :
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 _getErrorWithCode@src/mongo/shell/utils.js:25:13
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 doassert@src/mongo/shell/assert.js:16:14
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 assert.commandWorked@src/mongo/shell/assert.js:403:5
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 @unique_2dsphere_multikey_index.js:8:1
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 @unique_2dsphere_multikey_index.js:1:2
      [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 failed to load: unique_2dsphere_multikey_index.js
      
      Show
      python buildscripts/resmoke.py unique_2dsphere_multikey_index.js unique_2dsphere_multikey_index.js ( function () { "use strict" ; assert.writeOK(db.mycoll.insert({x: [{a: 1, b: 1}, {a: 2, b: 2}], geo: [0, 0]})); assert.writeOK(db.mycoll.insert({x: [{a: 1, b: 2}, {a: 2, b: 1}], geo: [0, 0]})); assert.commandWorked(db.mycoll.createIndex({ "x.a" : 1, "x.b" : 1}, {unique: true })); assert.commandWorked( db.mycoll.createIndex({ "x.a" : 1, "x.b" : 1, geo: "2dsphere" }, {unique: true })); })(); [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 2017-09-28T20:37:37.937-0400 E QUERY [thread1] Error: command failed: { [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 "ok" : 0, [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 "errmsg" : "E11000 duplicate key error collection: test.mycoll index: x.a_1_x.b_1_geo_2dsphere dup key: { : 1.0, : 1.0, : 1152921504606846977 }", [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 "code" : 11000, [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.940-0400 "codeName" : "DuplicateKey" [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 } : undefined : [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 _getErrorWithCode@src/mongo/shell/utils.js:25:13 [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 doassert@src/mongo/shell/assert.js:16:14 [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 assert.commandWorked@src/mongo/shell/assert.js:403:5 [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 @unique_2dsphere_multikey_index.js:8:1 [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 @unique_2dsphere_multikey_index.js:1:2 [js_test:unique_2dsphere_multikey_index] 2017-09-28T20:37:37.941-0400 failed to load: unique_2dsphere_multikey_index.js

      As mentioned in SERVER-23533, the key generation code for 2dsphere indexes produces keys by taking the Cartesian product of all distinct values (after expanding arrays) for each field. This means a 2dsphere index requires that all combinations of individual values for each field are unique rather than only the combinations of individual values for each field that appear together as array elements.

      Note: This issue was realized while discussing index key generation with eric.daniels@10gen.com and clarifying properties around multikey indexes.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: