Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #793 fix outdated nodejs MongoDB Atlas example #794

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aws-node-mongodb-atlas/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion aws-node-mongodb-atlas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
2 changes: 1 addition & 1 deletion aws-node-mongodb-atlas/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down