File tree 3 files changed +7
-6
lines changed
3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ const mongoClusterName = '';
10
10
const mongoUser = '' ;
11
11
const mongoDbName = '' ;
12
12
const mongoPass = '' ;
13
+ const clusterName = "" ;
13
14
14
- const mongoConnStr = `mongodb+srv://${ mongoUser } :${ mongoPass } @${ mongoClusterName } -tdoka.mongodb.net /${ mongoDbName } ?retryWrites=true` ;
15
+ const mongoConnStr = `mongodb+srv://${ mongoUser } :${ mongoPass } @${ mongoClusterName } /${ mongoDbName } ?retryWrites=true&w=majority&appName= ${ clusterName } ` ;
15
16
16
17
const getPetType = ( ) => {
17
18
const msNow = Date . now ( ) ;
@@ -52,17 +53,17 @@ const performQuery = async () => {
52
53
const app = express ( ) ;
53
54
54
55
app . get ( '/hello' , async function ( req , res ) {
55
- if ( ! client . isConnected ( ) ) {
56
+ // if (!client.isConnected()) { // no longer existing for newer mongodb lib versions
56
57
// Cold start or connection timed out. Create new connection.
57
58
try {
58
- await createConn ( ) ;
59
+ await createConn ( ) ; // no-op if already connected
59
60
} catch ( e ) {
60
61
res . json ( {
61
62
error : e . message ,
62
63
} ) ;
63
64
return ;
64
65
}
65
- }
66
+ // }
66
67
67
68
// Connection ready. Perform insert and return result.
68
69
try {
Original file line number Diff line number Diff line change 12
12
"dependencies" : {
13
13
"express" : " ^4.16.4" ,
14
14
"faker" : " ^4.1.0" ,
15
- "mongodb" : " ^3.1.13 " ,
15
+ "mongodb" : " ^6.8.0 " ,
16
16
"serverless-http" : " ^1.9.0"
17
17
}
18
18
}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ service: my-service # NOTE: update this with your service name
2
2
3
3
provider :
4
4
name : aws
5
- runtime : nodejs12 .x
5
+ runtime : nodejs20 .x
6
6
7
7
functions :
8
8
hello :
You can’t perform that action at this time.
0 commit comments