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

Descriptive error message for the inability to create unique indexes on arbitrary fields in sharded collections

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.1.12
    • None
    • Fully Compatible
    • Sharding 2019-01-14, Sharding 2019-01-28, Sharding 2019-02-11, Sharding 2019-02-25, Sharding 2019-05-06, Sharding 2019-05-20

    Description

      When creating a unique index on a collection and not every shard has a chunk of the collection, the error "request doesn't allow collection to be created implicitly" will supersede the unique index error message.
      Create index on a sharded collection with 1 chunk on shard A and no chunks on shard B:
       

      mongos> db.bar.createIndex( { z: 1 }, { unique: true });
      {
      	"ok" : 0,
      	"errmsg" : "request doesn't allow collection to be created implicitly",
      	"code" : 227,
      	"codeName" : "CannotImplicitlyCreateCollection",
      	"ns" : "test.bar",
      	"operationTime" : Timestamp(1543854707, 1),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1543854707, 41),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      

      Create index on a sharded collection with 1 chunk on shard A and 1 chunk on shard B:

      mongos> db.foo.createIndex( { z: 1}, { unique: true } )
      {
      	"raw" : {
      		"shardA/Kays-MacBook-Pro-2.local:27018,Kays-MacBook-Pro-2.local:27019,Kays-MacBook-Pro-2.local:27020" : {
      			"ok" : 0,
      			"errmsg" : "cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }",
      			"code" : 67,
      			"codeName" : "CannotCreateIndex"
      		},
      		"shardB/Kays-MacBook-Pro-2.local:27021,Kays-MacBook-Pro-2.local:27022,Kays-MacBook-Pro-2.local:27023" : {
      			"ok" : 0,
      			"errmsg" : "cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }",
      			"code" : 67,
      			"codeName" : "CannotCreateIndex"
      		}
      	},
      	"code" : 67,
      	"codeName" : "CannotCreateIndex",
      	"ok" : 0,
      	"errmsg" : "{ shardA/Kays-MacBook-Pro-2.local:27018,Kays-MacBook-Pro-2.local:27019,Kays-MacBook-Pro-2.local:27020: \"cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }\", shardB/Kays-MacBook-Pro-2.local:27021,Kays-MacBook-Pro-2.local:27022,Kays-MacBook-Pro-2.local:27023: \"cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }\" }",
      	"operationTime" : Timestamp(1543854778, 2),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1543854778, 2),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      

      Attachments

        Issue Links

          Activity

            People

              esha.maharishi@mongodb.com Esha Maharishi
              alyson.cabral@mongodb.com Alyson Cabral (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: