File tree 5 files changed +17
-24
lines changed
5 files changed +17
-24
lines changed Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ const mongoConnectionString = process.env.MONGO_URL;
14
14
const { ObjectId } = mongoose . Types ;
15
15
// Connect to MongoDB
16
16
mongoose . Promise = global . Promise ;
17
- mongoose . connect ( mongoConnectionString , {
18
- useNewUrlParser : true ,
19
- useUnifiedTopology : true
20
- } ) ;
17
+ mongoose . connect ( mongoConnectionString ) ;
21
18
mongoose . set ( 'strictQuery' , true ) ;
22
19
mongoose . connection . on ( 'error' , ( ) => {
23
20
console . error (
Original file line number Diff line number Diff line change @@ -22,8 +22,6 @@ const connectToMongoDB = async () => {
22
22
mongoose . set ( 'strictQuery' , true ) ;
23
23
24
24
await mongoose . connect ( mongoConnectionString , {
25
- useNewUrlParser : true ,
26
- useUnifiedTopology : true ,
27
25
serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
28
26
socketTimeoutMS : 45000 // 45 seconds timeout
29
27
} ) ;
Original file line number Diff line number Diff line change @@ -59,10 +59,7 @@ const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };
59
59
60
60
const mongoConnectionString = process . env . MONGO_URL ;
61
61
62
- mongoose . connect ( mongoConnectionString , {
63
- useNewUrlParser : true ,
64
- useUnifiedTopology : true
65
- } ) ;
62
+ mongoose . connect ( mongoConnectionString ) ;
66
63
mongoose . set ( 'strictQuery' , true ) ;
67
64
mongoose . connection . on ( 'error' , ( ) => {
68
65
console . error (
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };
14
14
15
15
const mongoConnectionString = process . env . MONGO_URL ;
16
16
17
- mongoose . connect ( mongoConnectionString , {
18
- useNewUrlParser : true ,
19
- useUnifiedTopology : true
20
- } ) ;
17
+ mongoose . connect ( mongoConnectionString ) ;
21
18
mongoose . set ( 'strictQuery' , true ) ;
22
19
mongoose . connection . on ( 'error' , ( ) => {
23
20
console . error (
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