🐞 fix(数据库): web和gm添加userlog副数据库

This commit is contained in:
luying
2023-04-28 13:45:47 +08:00
parent 8da660b81e
commit 064967ef9c
4 changed files with 42 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ import 'reflect-metadata'
import * as mongoose from 'mongoose';
import { Application, IBoot } from 'egg';
import { connectRedis } from './app/pubUtils/redis';
import { loadGmDb } from '@db/index';
import { loadGmDb, loadSubDb } from '@db/index';
import { SDK_TA_CONST, THINKING_DATA_MODE, THINKING_DATA_MODE_LIST } from '@consts';
const ThinkingAnalytics = require("thinkingdata-node");
@@ -19,6 +19,7 @@ export default class FooBoot implements IBoot {
// this is the last chance to modify the config.
await this.connectDB(this.app);
await this.connectGMDB(this.app);
await this.connectSubDB(this.app);
await this.connectRedis(this.app);
this.app.config.realEnv = this.app.config.env;
@@ -89,6 +90,20 @@ export default class FooBoot implements IBoot {
}
}
public async connectSubDB(app: Application) {
const { url, options } = app.config.submongoose||app.config.mongoose
try {
if (url) {
const connection = await mongoose.createConnection(url, options)
app.context.connectionGM = connection;
loadSubDb(connection);
console.log('******connectSubDB suc', url, options)
}
} catch(e) {
console.log(e)
}
}
public async connectRedis(app: Application) {
const { url, pw } = app.config.redis
if (url) {

View File

@@ -15,6 +15,11 @@ export default (appInfo: EggAppInfo) => {
options: { useNewUrlParser: true, useUnifiedTopology: true },
};
config.submongoose = {
url: 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504', // 内网
options: { useNewUrlParser: true, useUnifiedTopology: true },
};
config.redis = {
url: 'r-8vbkqfcnivt4ja3ndj.redis.zhangbei.rds.aliyuncs.com', // 内网
pw: 'hWCJ$HDajm9SN&&Z'