# MongoDB (/docs/v8/quickstart/mongodb)

> For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL.

Create a new Prisma 8 project with MongoDB using create-prisma@next.

Location: V8 > Quickstart > MongoDB

Create a Prisma 8 app with MongoDB, apply the first migration, and run your first query against seeded data.

> [!NOTE]
> The Prisma 8 Release Candidate is available
> 
> Prisma 8 is the next major version of Prisma ORM, now available as a Release Candidate. It’s the cutting-edge version of Prisma ORM and will become the future of Prisma, so we’d love for you to try it, explore what’s new, and [share your feedback in Discord](https://pris.ly/discord).
> 
> If you want to stay on the current generally available version of Prisma ORM, you can continue with [Prisma 7](https://www.prisma.io/docs/getting-started).

## Quick start [#quick-start]

  

#### bun

```bash
bunx create-prisma@next --provider mongodb
```

#### pnpm

```bash
pnpm dlx create-prisma@next --provider mongodb
```

#### yarn

```bash
yarn dlx create-prisma@next --provider mongodb
```

#### npm

```bash
npx create-prisma@next --provider mongodb
```

Run this from a Node.js 24 or newer environment. The command preselects MongoDB and prompts you for the contract authoring style (PSL or TypeScript) and your package manager.

Setup gives you the app template, a starter contract, `prisma-next.md`, project-level Prisma 8 skills for your coding agent, and package scripts for the database steps below. Sample users are seeded automatically the first time the app queries the database, so there is no separate seed step.

Prisma 8 needs a MongoDB replica set. MongoDB Atlas already gives you one; for local development, run a single-node replica set named `rs0` on port 27017 to match the generated connection string.

## 1. Set the database connection [#1-set-the-database-connection]

The scaffold writes a `.env` with a local replica-set connection string:

```text title=".env"
DATABASE_URL="mongodb://localhost:27017/mydb?replicaSet=rs0&directConnection=true"
```

The generated scripts read environment variables directly rather than `.env`, and the CLI and the app use different variable names: the CLI commands read `MONGODB_URL`, and the app reads `DATABASE_URL`. Export both in the shell you work in:

```bash
export MONGODB_URL="mongodb://localhost:27017/mydb?replicaSet=rs0&directConnection=true"
export DATABASE_URL="$MONGODB_URL"
```

If you use MongoDB Atlas, use the connection string from your Atlas cluster instead.

## 2. Create the migration plan [#2-create-the-migration-plan]

Create the first migration plan from the starter contract.

  

#### bun

```bash
bun run migration:plan --name init
```

#### pnpm

```bash
pnpm run migration:plan --name init
```

#### yarn

```bash
yarn migration:plan --name init
```

#### npm

```bash
npm run migration:plan -- --name init
```

The output reports the planned operations: creating the `users` and `posts` collections and a unique index on `users.email`.

## 3. Apply the migration [#3-apply-the-migration]

Apply the planned migration to MongoDB.

  

#### bun

```bash
bun run migrate
```

#### pnpm

```bash
pnpm run migrate
```

#### yarn

```bash
yarn migrate
```

#### npm

```bash
npm run migrate
```

The output ends with a summary like `Applied 1 migration(s) (3 operation(s)) across 1 contract space(s)`. If it fails with a connection error, confirm your MongoDB deployment is a replica set and `MONGODB_URL` is exported in this shell.

## 4. Run the app [#4-run-the-app]

Start the app and confirm the sample query runs successfully.

  

#### bun

```bash
bun run dev
```

#### pnpm

```bash
pnpm run dev
```

#### yarn

```bash
yarn dev
```

#### npm

```bash
npm run dev
```

Use the URL or terminal output shown by your template. You should see the seeded users returned from MongoDB.

## Next steps [#next-steps]

* Open `src/prisma/contract.prisma` or `src/prisma/contract.ts` and change the starter model.
* Use the [MongoDB existing-project guide](https://www.prisma.io/docs/v8/add-to-existing-project/mongodb) if you already have an app and database.
* Read the [Prisma 8 overview](https://www.prisma.io/docs/orm/v8) when you want the concepts behind contracts, query APIs, and migrations.

## Related pages

- [`PostgreSQL`](https://www.prisma.io/docs/v8/quickstart/postgresql): Create a new Prisma 8 project with PostgreSQL using create-prisma@next.