189 8069 5689

【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唯一索引的问题-创新互联
网站URL:http://jkwzsj.com/article/pcgsi.html

其他资讯