db_client = MgoClientDao()
db_client = db_client['admin']
result = db_client.command('shardcollection','db_name.table_name',
key={"ip":1})
新增一个分片键(hash)
db_client = MgoClientDao()
db_client = db_client['admin']
result = db_client.command('shardcollection','db_name.table_name',
key={"ip":"hashed"})
删除分片键
defdelete_sharding_key():
db_client = MgoClientDao(target=Config.db_target, socket_timeout_ms=Config.socket_timeout_ms)
db_client = db_client['config']
res = db_client["collection"].delete_one({"_id":'{}.{}'.format(Config.db_name, Config.collection_name)})
logger.info("collection res :{}".format(res.raw_result))
res = db_client["chunk"].delete_many({"ns":'{}.{}'.format(Config.db_name, Config.collection_name)})
logger.info("chunk res :{}".format(res.raw_result))
res = db_client["locks"].delete_one({"_id":'{}.{}'.format(Config.db_name, Config.collection_name)})
logger.info("locks res :{}".format(res.raw_result))