/mongodb-serverless

Primary LanguageTypeScriptMIT LicenseMIT

npm verison npm bundle size npm downloads

mongodb-serverless

Create MongoDB driver instances optimized for serverless environments.

Instances are cached between requests to minimize the number of connections and improve performance.

Installation

npm install mongodb-serverless

Usage

import { getMongoClient } from "mongodb-serverless";

export async function handler(event) {
  const client = getMongoClient(process.env.MONGO_URI, { appName: "app" });
  return await client.db().collection("docs").find({}).toArray();
}