广告
返回顶部
首页 > 资讯 > 数据库 >【Mongo】mongos shard 唯一索引的问题
  • 577
分享到

【Mongo】mongos shard 唯一索引的问题

2024-04-02 19:04:59 577人浏览 泡泡鱼
摘要

1.已经被sharding的文档建立唯一索引 monGos> db.testmongo.ensureIndex({'age':1,'name':1},{"unique":1})

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 唯一索引的前缀必须是分片健
您可能感兴趣的文档:

--结束END--

本文标题: 【Mongo】mongos shard 唯一索引的问题

本文链接: https://www.lsjlt.com/news/47243.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作