| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 合区方法:
- 1,redis中使用命令(举例:将10003的玩家合到10001)
- redis-cli -a "tmKjD1ENs3HfZ7adzLJO!" EVAL "local keys = redis.call('HKEYS', 'CUser_ServerId:'); local count = 0; for i,key in ipairs(keys) do if redis.call('HGET', 'CUser_ServerId:', key) == '10031' then redis.call('HSET', 'CUser_ServerId:', key, '10026'); count = count + 1; end; end; return count" 0
- redis-cli -n 1 -a "tmKjD1ENs3HfZ7adzLJO!" EVAL "local keys = redis.call('HKEYS', 'CUser_ServerId:'); local count = 0; for i,key in ipairs(keys) do if redis.call('HGET', 'CUser_ServerId:', key) == '10031' then redis.call('HSET', 'CUser_ServerId:', key, '10026'); count = count + 1; end; end; return count" 0
- 2,更新mongo中的x5_tk_login中的user_info中合服区的等级。
- // 更新服务器s1的玩家等级
- var server1Db = db.getSiblingDB("m5_x1_game_10001");
- var loginDb = db.getSiblingDB("x5_tk_login");
- var count1 = 0;
- server1Db.user.find().forEach(function(doc) {
- var result = loginDb.user_info.updateOne(
- {
- _id: doc._id
- },
- {
- $set: {
- level: doc.playerManager.level,
- update_time: new Date()
- }
- }
- );
-
- if (result.modifiedCount > 0) {
- count1++;
- }
- });
- print("服务器s1更新完成,更新了 " + count1 + " 条记录");
- 将mongo中的x5_tk_login中的user_info中10003的玩家serverId改成10001,
- db.user_info.updateMany(
- {
- "serverId": "10003" // 只匹配serverId为10003的文档
- },
- {
- $set: {
- "serverId": "10001"
- }
- }
- );
- 将mongo中10003区的集合user和guildinfo插入到10001区的数据库。
- db.getSiblingDB('m5_x1_game_10001').user.insertMany(
- db.getSiblingDB('m5_x1_game_10003').user.find().toArray(),
- { ordered: false }
- );
- 另一中方式:
- 先拷贝出来
- mongodump --uri='mongodb://root:StrongMongoPass123@localhost:27017/m5_x1_game_10007?authSource=admin' --collection user --out /data/mongodb/
- 再插入到目标数据库
- mongorestore --uri='mongodb://root:StrongMongoPass123@localhost:27017/?authSource=admin' --db m5_x1_game_10001 --collection user /data/mongodb/m5_x1_game_10002/user.bson
- db.getSiblingDB('m5_x1_game_10001').guildInfo.insertMany(
- db.getSiblingDB('m5_x1_game_10003').guildInfo.find().toArray(),
- { ordered: false }
- );
- db.server_info.updateMany(
- {
- "server_id": "10060" // 只匹配serverId为10003的文档
- },
- {
- $set: {
- "server_id": "10060",
- "port": "16160" ,
- "gm_port": "8160"
- }
- }
- );
- 1-19区合区保留1区
- 20-21保留20
- 22-25保留22
- 26-33保留30
|