項目中執(zhí)行
user_cli.admin.command({'shardcollection':'testdb.table2','key':{'id':1}})
開啟testdb.table2集合分片功能:
報:OperationFailure: sharding already enabled for collection testdb.table2 的錯誤洛心。
這時再切換到config庫查看:
mongos> use config
mongos> db.chunks.find()
{"_id":"testdb.table-id_MinKey","ns":"testdb.table","min":{"id":{"$minKey": 1}},"max":{"id":{"$maxKey": 1}},"shard":"autotestshd5ox8","lastmod": Timestamp(1,0),"lastmodEpoch": ObjectId("5b7c22cab2f293f9ed236190")}{"_id":"testdb.table2-id_MinKey","lastmod": Timestamp(2,0),"lastmodEpoch": ObjectId("5b7c2475b2f293f9ed23630a"),"ns":"testdb.table2","min":{"id":{"$minKey": 1}},"max":{"id": 1},"shard":"autotestshdcnas"}{"_id":"testdb.table2-id_1","lastmod": Timestamp(2,1),"lastmodEpoch": ObjectId("5b7c2475b2f293f9ed23630a"),"ns":"testdb.table2","min":{"id": 1},"max":{"id": 21},"shard":"autotestshd5ox8"}
發(fā)現(xiàn)testdb.table2的記錄已經(jīng)存在。
解決:在config庫里面刪除這個testdb.table2相關(guān)的信息相關(guān)的信息民褂。
mongos>use config
mongos>db.collections.remove( { _id: "testdb.table2" } )
mongos>db.chunks.remove( { ns: "testdb.table2" } )
mongos>db.locks.remove( { _id: "testdb.table2" } )
mongos>use admin
mongos>db.adminCommand("flushRouterConfig)