File tree Expand file tree Collapse file tree 5 files changed +24
-17
lines changed Expand file tree Collapse file tree 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;
1414const { ObjectId } = mongoose . Types ;
1515// Connect to MongoDB
1616mongoose . Promise = global . Promise ;
17- mongoose . connect ( mongoConnectionString ) ;
17+ mongoose . connect ( mongoConnectionString , {
18+ useNewUrlParser : true ,
19+ useUnifiedTopology : true
20+ } ) ;
1821mongoose . set ( 'strictQuery' , true ) ;
1922mongoose . connection . on ( 'error' , ( ) => {
2023 console . error (
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ const connectToMongoDB = async () => {
2222 mongoose . set ( 'strictQuery' , true ) ;
2323
2424 await mongoose . connect ( mongoConnectionString , {
25+ useNewUrlParser : true ,
26+ useUnifiedTopology : true ,
2527 serverSelectionTimeoutMS : 30000 , // 30 seconds timeout
2628 socketTimeoutMS : 45000 // 45 seconds timeout
2729 } ) ;
Original file line number Diff line number Diff line change @@ -59,7 +59,10 @@ const headers = { 'User-Agent': 'p5js-web-editor/0.0.1' };
5959
6060const mongoConnectionString = process . env . MONGO_URL ;
6161
62- mongoose . connect ( mongoConnectionString ) ;
62+ mongoose . connect ( mongoConnectionString , {
63+ useNewUrlParser : true ,
64+ useUnifiedTopology : true
65+ } ) ;
6366mongoose . set ( 'strictQuery' , true ) ;
6467mongoose . connection . on ( 'error' , ( ) => {
6568 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' };
1414
1515const mongoConnectionString = process . env . MONGO_URL ;
1616
17- mongoose . connect ( mongoConnectionString ) ;
17+ mongoose . connect ( mongoConnectionString , {
18+ useNewUrlParser : true ,
19+ useUnifiedTopology : true
20+ } ) ;
1821mongoose . set ( 'strictQuery' , true ) ;
1922mongoose . connection . on ( 'error' , ( ) => {
2023 console . error (
Original file line number Diff line number Diff line change @@ -76,19 +76,14 @@ app.use(cookieParser());
7676
7777mongoose . set ( 'strictQuery' , true ) ;
7878
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 ( ) ) ;
9287
9388app . use (
9489 session ( {
@@ -102,7 +97,8 @@ app.use(
10297 secure : false
10398 } ,
10499 store : new MongoStore ( {
105- clientPromise : clientInstancePromise
100+ clientPromise,
101+ autoReconnect : true
106102 } )
107103 } )
108104) ;
You can’t perform that action at this time.
0 commit comments