File tree 1 file changed +14
-10
lines changed
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -76,14 +76,19 @@ app.use(cookieParser());
76
76
77
77
mongoose . set ( 'strictQuery' , true ) ;
78
78
79
- const clientPromise = mongoose
80
- . connect ( mongoConnectionString , {
81
- useNewUrlParser : true ,
82
- useUnifiedTopology : true ,
83
- serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
84
- socketTimeoutMS : 45000 // 45 seconds timeout
85
- } )
86
- . then ( ( m ) => m . connection . getClient ( ) ) ;
79
+ async function connectToMongoDB ( ) {
80
+ try {
81
+ const mongooseConnection = await mongoose . connect ( mongoConnectionString , {
82
+ serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
83
+ socketTimeoutMS : 45000 // 45 seconds timeout
84
+ } ) ;
85
+ return mongooseConnection . connection . getClient ( ) ;
86
+ } catch ( err ) {
87
+ throw new Error ( 'MongoDB connection failed' , err ) ;
88
+ }
89
+ }
90
+
91
+ const clientInstancePromise = connectToMongoDB ( ) ;
87
92
88
93
app . use (
89
94
session ( {
@@ -97,8 +102,7 @@ app.use(
97
102
secure : false
98
103
} ,
99
104
store : new MongoStore ( {
100
- clientPromise,
101
- autoReconnect : true
105
+ clientPromise : clientInstancePromise
102
106
} )
103
107
} )
104
108
) ;
You can’t perform that action at this time.
0 commit comments