File tree 5 files changed +24
-17
lines changed
5 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ 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 ) ;
17
+ mongoose . connect ( mongoConnectionString , {
18
+ useNewUrlParser : true ,
19
+ useUnifiedTopology : true
20
+ } ) ;
18
21
mongoose . set ( 'strictQuery' , true ) ;
19
22
mongoose . connection . on ( 'error' , ( ) => {
20
23
console . error (
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ const connectToMongoDB = async () => {
22
22
mongoose . set ( 'strictQuery' , true ) ;
23
23
24
24
await mongoose . connect ( mongoConnectionString , {
25
+ useNewUrlParser : true ,
26
+ useUnifiedTopology : true ,
25
27
serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
26
28
socketTimeoutMS : 45000 // 45 seconds timeout
27
29
} ) ;
Original file line number Diff line number Diff line change @@ -59,7 +59,10 @@ 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 ) ;
62
+ mongoose . connect ( mongoConnectionString , {
63
+ useNewUrlParser : true ,
64
+ useUnifiedTopology : true
65
+ } ) ;
63
66
mongoose . set ( 'strictQuery' , true ) ;
64
67
mongoose . connection . on ( 'error' , ( ) => {
65
68
console . error (
Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ 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 ) ;
17
+ mongoose . connect ( mongoConnectionString , {
18
+ useNewUrlParser : true ,
19
+ useUnifiedTopology : true
20
+ } ) ;
18
21
mongoose . set ( 'strictQuery' , true ) ;
19
22
mongoose . connection . on ( 'error' , ( ) => {
20
23
console . error (
Original file line number Diff line number Diff line change @@ -76,19 +76,14 @@ app.use(cookieParser());
76
76
77
77
mongoose . set ( 'strictQuery' , true ) ;
78
78
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 ( ) ;
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 ( ) ) ;
92
87
93
88
app . use (
94
89
session ( {
@@ -102,7 +97,8 @@ app.use(
102
97
secure : false
103
98
} ,
104
99
store : new MongoStore ( {
105
- clientPromise : clientInstancePromise
100
+ clientPromise,
101
+ autoReconnect : true
106
102
} )
107
103
} )
108
104
) ;
You can’t perform that action at this time.
0 commit comments