网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

【Mongo】mongosshard唯一索引的问题-创新互联

创新互联建站-专业网站定制、快速模板网站建设、高性价比洛南网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式洛南网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖洛南地区。费用合理售后完善,10多年实体公司更值得信赖。 1.已经被sharding的文档建立唯一索引

  1. mongos> db.testmongo.ensureIndex({'age':1,'name':1},{"unique":1})
  2. {
  3.         "raw" : {
  4.                 "shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
  5.                         "createdCollectionAutomatically" : false,
  6.                         "numIndexesBefore" : 1,
  7.                         "ok" : 0,
  8.                         "errmsg" : "cannot create unique index over { age: 1.0, name: 1.0 } with shard key pattern { _id: 1.0 }",
  9.                         "code" : 67,
  10.                         "codeName" : "CannotCreateIndex",
  11.                         "$gleStats" : {
  12.                                 "lastOpTime" : {
  13.                                         "ts" : Timestamp(1529656402, 42),
  14.                                         "t" : NumberLong(6)
  15.                                 },
  16.                                 "electionId" : ObjectId("7fffffff0000000000000006")
  17.                         }
  18.                 },
  19.                 "shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
  20.                         "createdCollectionAutomatically" : true,
  21.                         "numIndexesBefore" : 1,
  22.                         "numIndexesAfter" : 2,
  23.                         "ok" : 1,
  24.                         "$gleStats" : {
  25.                                 "lastOpTime" : {
  26.                                         "ts" : Timestamp(1529656406, 2),
  27.                                         "t" : NumberLong(7)
  28.                                 },
  29.                                 "electionId" : ObjectId("7fffffff0000000000000007")
  30.                         }
  31.                 },
  32.                 "shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
  33.                         "createdCollectionAutomatically" : true,
  34.                         "numIndexesBefore" : 1,
  35.                         "numIndexesAfter" : 2,
  36.                         "ok" : 1,
  37.                         "$gleStats" : {
  38.                                 "lastOpTime" : {
  39.                                         "ts" : Timestamp(1529656406, 2),
  40.                                         "t" : NumberLong(6)
  41.                                 },
  42.                                 "electionId" : ObjectId("7fffffff0000000000000006")
  43.                         }
  44.                 }
  45.         },
  46.         "code" : 67,
  47.         "ok" : 0,
  48.         "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 }\" }"
  49. }
  50. mongos> db.testmongo.ensureIndex({'_id':1,'age':1,'name':1},{"unique":1})
  51. {
  52.         "raw" : {
  53.                 "shard1/172.31.32.223:27001,172.31.35.47:27001,172.31.37.105:27001" : {
  54.                         "createdCollectionAutomatically" : false,
  55.                         "numIndexesBefore" : 1,
  56.                         "numIndexesAfter" : 2,
  57.                         "ok" : 1,
  58.                         "$gleStats" : {
  59.                                 "lastOpTime" : {
  60.                                         "ts" : Timestamp(1529656437, 1),
  61.                                         "t" : NumberLong(6)
  62.                                 },
  63.                                 "electionId" : ObjectId("7fffffff0000000000000006")
  64.                         }
  65.                 },
  66.                 "shard2/172.31.32.223:27002,172.31.35.47:27002,172.31.37.105:27002" : {
  67.                         "createdCollectionAutomatically" : false,
  68.                         "numIndexesBefore" : 2,
  69.                         "numIndexesAfter" : 3,
  70.                         "ok" : 1,
  71.                         "$gleStats" : {
  72.                                 "lastOpTime" : {
  73.                                         "ts" : Timestamp(1529656437, 1),
  74.                                         "t" : NumberLong(7)
  75.                                 },
  76.                                 "electionId" : ObjectId("7fffffff0000000000000007")
  77.                         }
  78.                 },
  79.                 "shard3/172.31.32.223:27003,172.31.35.47:27003,172.31.37.105:27003" : {
  80.                         "createdCollectionAutomatically" : false,
  81.                         "numIndexesBefore" : 2,
  82.                         "numIndexesAfter" : 3,
  83.                         "ok" : 1,
  84.                         "$gleStats" : {
  85.                                 "lastOpTime" : {
  86.                                         "ts" : Timestamp(1529656437, 1),
  87.                                         "t" : NumberLong(6)
  88.                                 },
  89.                                 "electionId" : ObjectId("7fffffff0000000000000006")
  90.                         }
  91.                 }
  92.         },
  93.         "ok" : 1
  94. }

已经被shard的collection 唯一索引的前缀必须是分片健

分享题目:【Mongo】mongosshard唯一索引的问题-创新互联
文章网址:http://bjjierui.cn/article/pcgsi.html

其他资讯