core: db: add collectionMap support

This commit is contained in:
undefined committed 2024-10-08 18:56:08 +08:00
1 parent 4b7a080de7
commit 5f8785362c
1 file changed
+4 -2
+4 -2
View File
@@ -22,6 +22,7 @@ interface MongoConfig {
url?: string, url?: string,
uri?: string, uri?: string,
prefix?: string, prefix?: string,
collectionMap?: Record<string, string>,
} }
class MongoService { class MongoService {
@@ -54,8 +55,9 @@ class MongoService {
} }
public collection<K extends keyof Collections>(c: K) { public collection<K extends keyof Collections>(c: K) {
if (this.opts.prefix) return this.db.collection<Collections[K]>(`${this.opts.prefix}.${c}`); let coll = this.opts.prefix ? `${this.opts.prefix}.${c}` : c;
return this.db.collection<Collections[K]>(c); if (this.opts.collectionMap?.[coll]) coll = this.opts.collectionMap[coll];
return this.db.collection<Collections[K]>(coll);
} }
public async fixExpireAfter() { public async fixExpireAfter() {