【Mongo】mongos shard 唯一索引的問題
1.已經被sharding的文件建立唯一索引
-
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 唯一索引的字首必須是分片健
2.已經建立唯一索引的collection去shard
-
mongos> db.testtt.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "welike_mongo.testtt"
},
{
"v" : 2,
"unique" : true,
"key" : {
"age" : 1,
"name" : 1
},
"name" : "age_1_name_1",
"ns" : "welike_mongo.testtt"
}
]
-
mongos> sh.shardCollection("welike_mongo.testtt",{_id:1})
-
{
-
"ok" : 0,
-
"errmsg" : "can't shard collection 'welike_mongo.testtt' with unique index on { age: 1.0, name: 1.0 } and proposed shard key { _id: 1.0 }. Uniqueness can't be maintained unless shard key is a prefix"
-
}
-
mongos> sh.shardCollection("welike_mongo.testtt",{'name':1})
-
{
-
"ok" : 0,
-
"errmsg" : "can't shard collection 'welike_mongo.testtt' with unique index on { age: 1.0, name: 1.0 } and proposed shard key { name: 1.0 }. Uniqueness can't be maintained unless shard key is a prefix"
-
}
-
mongos> sh.shardCollection("welike_mongo.testtt",{'age':1})
- { "collectionsharded" : "welike_mongo.testtt", "ok" : 1 }
已建立唯一索引的collect 去shard 。分片欄位必須是唯一索引的字首
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2156524/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料庫表的唯一索引問題資料庫索引
- mongo 索引解析Go索引
- 管理索引mongo索引Go
- MyBatisPlus解決邏輯刪除與唯一索引的相容問題MyBatis索引
- 唯一索引索引
- MongoDB之索引(唯一索引)MongoDB索引
- 唯一索引和非唯一索引ROWID儲存的區別索引
- 【Mongo】MongoDB索引管理-索引的建立、檢視、刪除MongoDB索引
- MySQL <唯一索引>MySql索引
- MySQL 唯一索引和普通索引MySql索引
- spring data mongo @Field 失效問題SpringGo
- Oracle主鍵、唯一鍵與唯一索引的區別Oracle索引
- 函式索引的問題函式索引
- ES ElasticSearch 7.x 下動態擴大索引的shard數量Elasticsearch索引
- 主鍵和唯一索引的區別索引
- 唯一索引操作可能產生的鎖索引
- 關於唯一性索引造成堵塞和非唯一性索引造成堵塞的區別索引
- kk系統索引的問題索引
- 唯一性約束和唯一性索引的區別索引
- mongo shell中特殊判斷符號轉義的問題Go符號
- mysql唯一索引是什麼MySql索引
- MySQL實戰45講——普通索引和唯一索引MySql索引
- MYSQL中的普通索引,主健,唯一,全文索引區別MySql索引
- sql shard/partitionSQL
- mysql的唯一索引不會利用change bufferMySql索引
- 效能測試中的唯一標識問題研究
- Mongos 與叢集均衡Go
- 索引無法消除排序的問題索引排序
- 關於函式索引的問題?函式索引
- Oracle 索引的三個問題(轉)Oracle索引
- 唯一索引,可以在索引列插入多個null嗎索引Null
- Oracle主鍵約束、唯一鍵約束、唯一索引的區別(轉)Oracle索引
- 筆記 mongo查詢慢日誌,建立索引筆記Go索引
- 轉載-treedump索引讀取索引儲存的資料值--非唯一性索引索引
- 聊一聊MySQL索引失效的問題MySql索引
- 關於索引是否該rebuild的問題索引Rebuild
- Matlab轉python的索引問題MatlabPython索引
- mongodb之shard分片MongoDB