Database for Developers
Get started with Vercel and MongoDB Atlas, the world’s leading modern, multi-cloud database. Atlas combines the flexible document model with a suite of data services to give you a versatile cloud database that simplifies everything you build. Build your next project with MongoDB Atlas’ AI-ready architecture, which comes with native support for vector search, full-text search, hybrid search, and real-time operational queries.
Choose from free, dedicated, and flexible provisioning, with options for every use case. MongoDB Atlas is the most effective way to deploy MongoDB.
Ready to build? Check out our documentation.
Create a new Next.js app with MongoDB pre-configured.
npx create-next-app --example with-mongodb my-mongodb-appcd my-mongodb-appFirst, make sure you have connected this database to a Vercel project (see Projects tab on the left).
Then, run vercel link in the CLI to link to the project locally.
Run vercel env pull to make the latest environment variables available to your project locally.
Run the development server with npm run dev then go to http://localhost:3000 in a browser to see your app.
When using MongoDB with Vercel Functions, add connection pool management to prevent connection leaks in serverless environments.
npm install @vercel/functionslib/mongodb.ts file:import { MongoClient } from "mongodb";import { attachDatabasePool } from "@vercel/functions";
// ... existing connection setup ...
const client = new MongoClient(uri, options);attachDatabasePool(client);This ensures database connections are properly managed when your functions suspend and resume, improving performance and preventing connection exhaustion. Read more:
Please also review MongoDB's best practices guide.
The integration automatically configures these variables for secure database connections:
MONGODB_URITo learn more, check out the getting started tutorial and MongoDB Atlas Vercel Native Integration guide.
Starter Templates
View all templates