@@ -10,7 +10,7 @@ import {
1010} from '@nestjs/common' ;
1111import { ModuleRef } from '@nestjs/core' ;
1212import * as mongoose from 'mongoose' ;
13- import { defer } from 'rxjs' ;
13+ import { defer , lastValueFrom } from 'rxjs' ;
1414import { getConnectionToken , handleRetry } from './common/mongoose.utils' ;
1515import {
1616 MongooseModuleAsyncOptions ,
@@ -53,18 +53,14 @@ export class MongooseCoreModule implements OnApplicationShutdown {
5353 const connectionProvider = {
5454 provide : mongooseConnectionName ,
5555 useFactory : async ( ) : Promise < any > =>
56- await defer ( async ( ) =>
57- mongooseConnectionFactory (
58- mongoose . createConnection ( uri , {
59- useNewUrlParser : true ,
60- useUnifiedTopology : true ,
61- ...mongooseOptions ,
62- } ) ,
63- mongooseConnectionName ,
64- ) ,
65- )
66- . pipe ( handleRetry ( retryAttempts , retryDelay ) )
67- . toPromise ( ) ,
56+ await lastValueFrom (
57+ defer ( async ( ) =>
58+ mongooseConnectionFactory (
59+ mongoose . createConnection ( uri , mongooseOptions ) ,
60+ mongooseConnectionName ,
61+ ) ,
62+ ) . pipe ( handleRetry ( retryAttempts , retryDelay ) ) ,
63+ ) ,
6864 } ;
6965 return {
7066 module : MongooseCoreModule ,
@@ -98,23 +94,22 @@ export class MongooseCoreModule implements OnApplicationShutdown {
9894 const mongooseConnectionFactory =
9995 connectionFactory || ( ( connection ) => connection ) ;
10096
101- return await defer ( async ( ) =>
102- mongooseConnectionFactory (
103- mongoose . createConnection ( mongooseModuleOptions . uri as string , {
104- useNewUrlParser : true ,
105- useUnifiedTopology : true ,
106- ...mongooseOptions ,
107- } ) ,
108- mongooseConnectionName ,
109- ) ,
110- )
111- . pipe (
97+ return await lastValueFrom (
98+ defer ( async ( ) =>
99+ mongooseConnectionFactory (
100+ mongoose . createConnection (
101+ mongooseModuleOptions . uri as string ,
102+ mongooseOptions ,
103+ ) ,
104+ mongooseConnectionName ,
105+ ) ,
106+ ) . pipe (
112107 handleRetry (
113108 mongooseModuleOptions . retryAttempts ,
114109 mongooseModuleOptions . retryDelay ,
115110 ) ,
116- )
117- . toPromise ( ) ;
111+ ) ,
112+ ) ;
118113 } ,
119114 inject : [ MONGOOSE_MODULE_OPTIONS ] ,
120115 } ;
0 commit comments