Upgrade from MongoDB Beta
Introduction
This guide helps you migrate from the Prisma 1 MongoDB Beta to MongoDB on Prisma ORM 2 or later. To learn more about the differences between Prisma 1 and Prisma ORM 2.x and later, refer to this document.
The scope of this guide is to give you the workflow necessary to perform the migration and highlight some of the problems you might encounter.
We unfortunately can't cover all possible scenarios or changes required, but this guide should help you on your journey. Join our Discord or create an issue on Github with any questions.
Perform this migration on your staging environment before trying this in production!
Requirements
- Must be running MongoDB 4.2+ as a replica set (MongoDB Atlas does this for you automatically)
- Node.js: see system requirements
- TypeScript: see system requirements
Installing Prisma ORM 3.12.0 or later
In your project directory run the following commands:
$ npm install prisma@latest
$ npx prisma init --datasource-provider=mongodb
This should create the following files:
prisma/schema.prisma
: An initial Prisma schema.env
: Environment file where you'll store your connection string
If you see the following error:
ERROR File schema.prisma already exists in your project.
Please try again in a project that is not yet using Prisma.
You have likely a prisma/
directory in your project already. Rename that directory to something like _prisma/
and try again
Find the Connection String to your MongoDB Database
Next you'll want to find the connection string to your MongoDB database. You should be able to find it in your docker-compose.yml
file or on MongoDB Atlas. It's what you'd pass to MongoDB Compass. The connection string should look something like this:
mongodb://<user>:<pass>@<host>:27017
The database that stores application data in Prisma 1 is called default_default
, so we'll add that to the end of the connection string and update the DATABASE_URL
key in the .env
file
DATABASE_URL="mongodb://prisma:prisma@localhost:27017/default_default"