【Mongo】mongos shard 唯一索引的问题
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,1.已经被sharding的文档建立唯一索引mongos> db.testmongo.ensureIndex({'age':1,'name':1},{"unique":1}){"raw" : {"sh
千家信息网最后更新 2025年02月02日【Mongo】mongos shard 唯一索引的问题
已经被shard的collection 唯一索引的前缀必须是分片健
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 }
索引
前缀
字段
文档
问题
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
根据网络安全任何个人
网络安全展厅方案
服务器网站搭建工具
网络安全主题班会稿
数据库中csrq
网络安全宣传周安全贴士
方舟服务器一共多少人
安徽综合软件开发近期价格
服务器游戏挂机
网络安全中年人的心理危机
简单 ios软件开发
中国知名软件开发人才
橙绩上海网络技术有限公司
小白服务器管理工具
光速输入法软件开发
育碧为什么不换服务器
检测数据库错误
贵州6台网络安全教育
helen网络安全
图纸软件开发
数据库课程设计题目doc下载
网络安全运维服务月报
海中王互联网科技
幼儿网络安全教育互动游戏
单机魔域数据库
云服务器迁移
数据库与工作区的关系
女性专用服务器
cf总是出现选择该服务器人多
云服务器中继