From 3d4a576c066a402f6f77d683e922b118760c27a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20S=C3=BCdkamp?= Date: Wed, 7 Aug 2024 19:40:41 +0200 Subject: [PATCH] Fix #793 fix outdated example --- aws-node-mongodb-atlas/handler.js | 9 +++++---- aws-node-mongodb-atlas/package.json | 2 +- aws-node-mongodb-atlas/serverless.yml | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/aws-node-mongodb-atlas/handler.js b/aws-node-mongodb-atlas/handler.js index 9580fe626..36b74ad35 100644 --- a/aws-node-mongodb-atlas/handler.js +++ b/aws-node-mongodb-atlas/handler.js @@ -10,8 +10,9 @@ const mongoClusterName = ''; const mongoUser = ''; const mongoDbName = ''; const mongoPass = ''; +const clusterName = ""; -const mongoConnStr = `mongodb+srv://${mongoUser}:${mongoPass}@${mongoClusterName}-tdoka.mongodb.net/${mongoDbName}?retryWrites=true`; +const mongoConnStr = `mongodb+srv://${mongoUser}:${mongoPass}@${mongoClusterName}/${mongoDbName}?retryWrites=true&w=majority&appName=${clusterName}`; const getPetType = () => { const msNow = Date.now(); @@ -52,17 +53,17 @@ const performQuery = async () => { const app = express(); app.get('/hello', async function (req, res) { - if (!client.isConnected()) { + // if (!client.isConnected()) { // no longer existing for newer mongodb lib versions // Cold start or connection timed out. Create new connection. try { - await createConn(); + await createConn(); // no-op if already connected } catch (e) { res.json({ error: e.message, }); return; } - } + // } // Connection ready. Perform insert and return result. try { diff --git a/aws-node-mongodb-atlas/package.json b/aws-node-mongodb-atlas/package.json index 152c3b4c6..247df6efe 100644 --- a/aws-node-mongodb-atlas/package.json +++ b/aws-node-mongodb-atlas/package.json @@ -12,7 +12,7 @@ "dependencies": { "express": "^4.16.4", "faker": "^4.1.0", - "mongodb": "^3.1.13", + "mongodb": "^6.8.0", "serverless-http": "^1.9.0" } } diff --git a/aws-node-mongodb-atlas/serverless.yml b/aws-node-mongodb-atlas/serverless.yml index 0117fd8ae..e6c1f3c64 100644 --- a/aws-node-mongodb-atlas/serverless.yml +++ b/aws-node-mongodb-atlas/serverless.yml @@ -2,7 +2,7 @@ service: my-service # NOTE: update this with your service name provider: name: aws - runtime: nodejs12.x + runtime: nodejs20.x functions: hello: