Mongoose document says we can set global options like mongoose.set('returnOriginal', false).
Now I am using @nestjs/mongoose in nestjs, but I can't find a document describes how to do this global options setting.
I do find a way to change the setting by InjectConnection
import { Module } from '@nestjs/common';
import { MongooseModule, InjectConnection } from '@nestjs/mongoose';
import { Connection } from 'mongoose';
...
@Module({
imports: [
MongooseModule.forRootAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
uri: configService.get('DB_URI'),
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
}),
}),
...
],
})
export class AppModule {
constructor(@InjectConnection() private readonly connection: Connection) {
connection.base.set('returnOriginal', false);
}
}
This code works fine for me. However in @types/mongoose, there is no property base.set in type Connection. I have to omit the type definition for injected connection.
My question is whether this is a standard approach to set mongoose global options? If not, how can I do this?