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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL

      Description

      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"
      	}
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: