fix db mock

This commit is contained in:
undefined committed 2020-08-20 17:36:37 +08:00
1 parent af9a8fb206
commit 12af2f7542
2 files changed
+22 -1

No files matched your search

+20 -1
View File
@@ -4,6 +4,8 @@ import mongodb, { Db, MongoClient } from 'mongodb';
export let db: Db = null;
export let client: MongoClient = null;
export let db2: Db = null;
export let client2: MongoClient = null;
export const bus = new EventEmitter();
@@ -15,7 +17,16 @@ mongodb.MongoClient.connect(
// @ts-ignore
db = c.db(global.__MONGO_DB_NAME__);
client = c;
bus.emit('connect');
mongodb.MongoClient.connect(
// @ts-ignore
global.__MONGO_URI__,
{ useNewUrlParser: true, useUnifiedTopology: true },
).then((c2) => {
// @ts-ignore
db2 = c2.db(global.__MONGO_DB_NAME__);
client2 = c2;
bus.emit('connect');
});
});
export function collection(c: string) {
@@ -26,6 +37,14 @@ export function getClient() {
return client;
}
export function getClient2() {
return client2;
}
export function getDb() {
return db;
}
export function getDb2() {
return db2;
}