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

Creating a compound unique index with _id is successful, even when _id is not the shard key

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query
    • ALL

      where test.bar
      shard key:

      { "x" : 1 }

      unique: true

      mongos> db.bar.createIndex( { _id: 1, x: 1, c: 1}, { unique: true });
      {
      	"raw" : {
      		"shardA/Kays-MacBook-Pro-2.local:27018,Kays-MacBook-Pro-2.local:27019,Kays-MacBook-Pro-2.local:27020" : {
      			"createdCollectionAutomatically" : false,
      			"numIndexesBefore" : 4,
      			"numIndexesAfter" : 5,
      			"ok" : 1
      		},
      		"shardB/Kays-MacBook-Pro-2.local:27021,Kays-MacBook-Pro-2.local:27022,Kays-MacBook-Pro-2.local:27023" : {
      			"ok" : 0,
      			"errmsg" : "request doesn't allow collection to be created implicitly",
      			"code" : 227,
      			"codeName" : "CannotImplicitlyCreateCollection",
      			"ns" : "test.bar"
      		}
      	},
      	"ok" : 1,
      	"operationTime" : Timestamp(1543854685, 3),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1543854685, 5),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      
      mongos> db.bar.getIndexes()
      [
      	{
      		"v" : 2,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "test.bar"
      	},
      	{
      		"v" : 2,
      		"unique" : true,
      		"key" : {
      			"x" : 1
      		},
      		"name" : "x_1",
      		"ns" : "test.bar"
      	},
      {
      		"v" : 2,
      		"unique" : true,
      		"key" : {
      			"_id" : 1,
      			"x" : 1,
      			"c" : 1
      		},
      		"name" : "_id_1_x_1_c_1",
      		"ns" : "test.bar"
      	}
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            alyson.cabral@mongodb.com Alyson Cabral (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: