【Mongo】mongosshard唯一索引的问题-创新互联
创新互联建站-专业网站定制、快速模板网站建设、高性价比洛南网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式洛南网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖洛南地区。费用合理售后完善,10多年实体公司更值得信赖。 1.已经被sharding的文档建立唯一索引
已经被shard的collection 唯一索引的前缀必须是分片健
文章题目:【Mongo】mongosshard唯一索引的问题-创新互联
本文路径:http://scjbc.cn/article/pcgsi.html
- 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 唯一索引的前缀必须是分片健
文章题目:【Mongo】mongosshard唯一索引的问题-创新互联
本文路径:http://scjbc.cn/article/pcgsi.html