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

This commit is contained in:
luying
2023-04-28 13:46:33 +08:00
parent 8da660b81e
commit 064967ef9c
4 changed files with 42 additions and 2 deletions
+16 -1
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) {