【发布时间】:2019-08-22 12:01:19
【问题描述】:
我需要更改我的查询在 Nestjs 应用中指向的位置。
我正在使用带有版本的 Angular 应用程序,因此我必须在后端使用 Mongoose 和 Nestjs 动态更改集合甚至数据库。
我想我必须更改提供程序中的目标,并尝试根据用户在前面选择的版本动态更改它。
反正我有这样的东西
import { Connection } from 'mongoose';
import { TestSchema } from './schemas/test.schema';
export const testProviders = [
{
provide: 'TestModelToken',
useFactory: (connection: Connection) =>
connection.model('Test', FilterSchema, 'tests'),
inject: ['DbConnectionToken'],
},
];
然后,例如,我想将其更改为动态指向此集合
tests_24_04_2019
我的服务看起来像
@Injectable()
export class TestsService {
constructor(
@Inject("TestModelToken") private readonly testModel: Model<Test>,
谢谢,感谢您的帮助
【问题讨论】:
-
你用的是什么版本的nestjs?
-
Nestjs 5.4.x :)
标签: node.js angular typescript mongoose nestjs