-
monGos> db.testmongo.ensureIndex({'age':1,'name':1},{"unique":1})
-
{
-
"raw" : {
-
"shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 1,
-
"ok" : 0,
-
"errmsg" : "cannot create unique index over { age: 1.0, name: 1.0 } with shard key pattern { _id: 1.0 }",
-
"code" : 67,
-
"codeName" : "CannotCreateIndex",
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656402, 42),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
},
-
"shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
-
"createdCollectionAutomatically" : true,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656406, 2),
-
"t" : NumberLong(7)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000007")
-
}
-
},
-
"shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
-
"createdCollectionAutomatically" : true,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656406, 2),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
}
-
},
-
"code" : 67,
-
"ok" : 0,
-
"errmsg" : "{ shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001: \"cannot create unique index over { age: 1.0, name: 1.0 } with shard key pattern { _id: 1.0 }\" }"
-
}
-
mongos> db.testmongo.ensureIndex({'_id':1,'age':1,'name':1},{"unique":1})
-
{
-
"raw" : {
-
"shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 1,
-
"numIndexesAfter" : 2,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
},
-
"shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 2,
-
"numIndexesAfter" : 3,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(7)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000007")
-
}
-
},
-
"shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
-
"createdCollectionAutomatically" : false,
-
"numIndexesBefore" : 2,
-
"numIndexesAfter" : 3,
-
"ok" : 1,
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1529656437, 1),
-
"t" : NumberLong(6)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000006")
-
}
-
}
-
},
-
"ok" : 1
-
}
已经被shard的collection 唯一索引的前缀必须是分片健
--结束END--
本文标题: 【Mongo】mongos shard 唯一索引的问题
本文链接: https://www.lsjlt.com/news/47243.html(转载时请注明来源链接)
有问题或投稿请发送至:
邮箱/279061341@qq.com QQ/279061341
0