In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Documents that have been uniquely indexed by sharding mongos > db.testmongo.ensureIndex ({'age':1,'name':1}, {"unique": 1})
{
"raw": {
"shard1/172.31.32.223:27001172.31.35.47:27001172.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:27002172.31.35.47:27002172.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:27003172.31.35.47:27003172.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:27001172.31.35.47:27001172.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:27001172.31.35.47:27001172.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:27002172.31.35.47:27002172.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:27003172.31.35.47:27003172.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
}
The prefix of the collection unique index that has been shard must be a sharding key.
two。 Collection that has created a unique index goes to shardmongos > 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} collect to shard that has created a unique index. The shard field must be the prefix of the unique index
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.