Skip to content

Instantly share code, notes, and snippets.

@LearnWebCode
LearnWebCode / yourFunction.js
Created November 13, 2020 22:19
Connect to MongoDB / Atlas within Netlify / AWS Lambda Serverless Function File
const mongodb = require("mongodb")
exports.handler = async function (event, context) {
const client = await mongodb.connect(process.env.CONNECTIONSTRING, { useUnifiedTopology: true })
const db = client.db()
try {
const dogs = await db.collection("pets").find({ species: "dog" }).toArray()
client.close()
return {