Create a new app with MongoDB
Create a new Prisma ORM project with MongoDB using create-prisma@latest.
This page uses MongoDB. Use PostgreSQL instead.
Create a Prisma ORM app with MongoDB, apply the first migration, and run your first query against seeded data.
Prisma ORM 8 is a release candidate. Prisma ORM 7 remains fully supported; its docs live at /orm/v7 and its setup paths at /v7/getting-started.
For what release candidate means, when the final release is expected, and how to stay on version 7, see Release status.
Quick start
You need Node.js 22.18 or newer on the 22 line, 24.11 or newer on the 24 line, or 26 or newer; Node.js 24 is recommended. The npm that ships with your Node.js release works; on Node.js 22 that is npm 10. Supported versions has every floor.
npm create prisma@latest -- --provider mongodb --no-deployThe command preselects MongoDB and prompts you for the project name, the template, the language you write your contract in (the contract is what Prisma ORM 7 called the schema, and you write it in Prisma Schema Language, as in schema.prisma, or in TypeScript), your package manager, and whether to install agent skills. If you would rather add Prisma ORM to a project by hand, without the generated template, follow Set up Prisma ORM from scratch, which uses PostgreSQL.
Setup gives you the app template, a starter contract, prisma-8.md (a short quick reference for writing your first typed query), project-level Prisma ORM skills for your coding agent, and package scripts for the database steps below. Answer no at the skills prompt, or pass --skills none, to skip the agent skill files; to remove them later, see skills sync and the skills config section. Sample users are seeded automatically the first time the app queries the database, so there is no separate seed step.
1. Set the database connection
Run the remaining steps in the new project directory, such as cd my-app for a project named my-app. The scaffold writes a .env there with a local connection string:
DATABASE_URL="mongodb://localhost:27017/mydb?replicaSet=rs0&directConnection=true"Nothing in the generated project loads .env, so export DATABASE_URL in the shell you work in. Both the prisma commands and the app read it from there:
export DATABASE_URL="mongodb://localhost:27017/mydb?replicaSet=rs0&directConnection=true"The setup output also asks you to set MONGODB_URL. That variable is only for running or deploying the app with Prisma Composer, and this quickstart does not need it.
The string names a replica set, rs0, but because it also sets directConnection=true, it connects to a standalone mongod on port 27017 as well, so you can use it as it is with either. A standalone server is enough for this quickstart, because a replica set is only needed for transactions and change streams.
If you use MongoDB Atlas, which is already a replica set, use the connection string from your Atlas cluster instead. If you have no MongoDB server yet, A database on your machine shows how to run one in Docker.
2. Create the migration plan
Create the first migration plan from the starter contract.
npm run migration:plan -- --name initThe output reports the planned operations: creating the users and posts collections and a unique index on users.email.
3. Apply the migration
Apply the planned migration to MongoDB:
npm run migrate -- --advance-ref db--advance-ref db writes migrations/app/refs/db.json, the db ref, which records the contract state your development database is now at. Your next migration plan starts from it. Without it, the next npm run migration:plan stops with MIGRATION.PLAN_ORIGIN_UNKNOWN, because migrations exist but nothing says which one your database has.
The output includes Applied 1 migration(s) (3 operation(s)) across 1 contract space(s) and ends with a line starting Advanced ref "db". If it fails with a connection error, confirm DATABASE_URL is exported in this shell and points at a running MongoDB server.
The 1 contract space in the summary is the migration history for your own models. Prisma ORM calls it the app contract space, and its migrations are in migrations/app/.
4. Run the app
Start the app and confirm the sample query runs successfully.
npm run devUse the URL or terminal output shown by your template. You should see the seeded users returned from MongoDB.
Next steps
- Open
src/prisma/contract.prismaorsrc/prisma/contract.tsand change the starter model. Then runnpm run contract:emit,npm run migration:plan -- --name <name>, andnpm run migrate -- --advance-ref db. Withoutcontract:emit,migration planreads the contract from before your change and reportsNo changes detected. - If you already have an app, follow Add Prisma ORM and MongoDB to an existing app when its database is empty, or Add Prisma ORM to an existing MongoDB database when the database already has collections.
- Read the Prisma ORM overview when you want the concepts behind contracts, query APIs, and migrations.
Updated