Skip to content

Commit bcb7848

Browse files
ankur-archaidankmcalister
authored andcommitted
feat: add mention of mongo support coming for P7 (#7271)
* feat: add mention of mongo support coming for mongo * fix: refinements * Update content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx
1 parent 6a62234 commit bcb7848

13 files changed

Lines changed: 166 additions & 83 deletions

File tree

content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ This command does a few things:
9090
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9191
- Creates a new Prisma Postgres database (when using `--db` flag)
9292
- Creates a `.env` file in the root directory for environment variables
93-
- Generates the Prisma Client in the `generated/prisma/` directory
9493
- Creates a `prisma.config.ts` file for Prisma configuration
9594

9695
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ This command does a few things:
8484

8585
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
8686
- Creates a `.env` file in the root directory for environment variables
87-
- Generates the Prisma Client in the `generated/prisma/` directory
8887
- Creates a `prisma.config.ts` file for Prisma configuration
8988

9089
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ This command does a few things:
9494

9595
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9696
- Creates a `.env` file in the root directory for environment variables
97-
- Generates the Prisma Client in the `generated/prisma/` directory
9897
- Creates a `prisma.config.ts` file for Prisma configuration
9998

10099
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/400-mysql.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ This command does a few things:
9090

9191
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9292
- Creates a `.env` file in the root directory for environment variables
93-
- Generates the Prisma Client in the `generated/prisma/` directory
9493
- Creates a `prisma.config.ts` file for Prisma configuration
9594

9695
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/500-sql-server.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ This command does a few things:
8989

9090
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9191
- Creates a `.env` file in the root directory for environment variables
92-
- Generates the Prisma Client in the `generated/prisma/` directory
9392
- Creates a `prisma.config.ts` file for Prisma configuration
9493

9594
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/600-planetscale.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ This command does a few things:
9393

9494
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9595
- Creates a `.env` file in the root directory for environment variables
96-
- Generates the Prisma Client in the `generated/prisma/` directory
9796
- Creates a `prisma.config.ts` file for Prisma configuration
9897

9998
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ This command does a few things:
8888

8989
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
9090
- Creates a `.env` file in the root directory for environment variables
91-
- Generates the Prisma Client in the `generated/prisma/` directory
9291
- Creates a `prisma.config.ts` file for Prisma configuration
9392

9493
The generated `prisma.config.ts` file looks like this:

content/100-getting-started/02-prisma-orm/100-quickstart/800-mongodb.mdx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import NextSteps from '../../_components/_next-steps.mdx'
1212

1313
[MongoDB](https://www.mongodb.com) is a popular NoSQL document database. In this guide, you will learn how to set up a new TypeScript project from scratch, connect it to MongoDB using Prisma ORM, and generate a Prisma Client for easy, type-safe access to your database.
1414

15-
:::warning[Do not upgrade to Prisma ORM v7 if you are using MongoDB]
15+
:::warning[MongoDB support for Prisma ORM v7]
1616

17-
Prisma ORM v7 is not yet compatible with MongoDB. Please use Prisma ORM v6 instead. Support for MongoDB is coming in a future release.
17+
**MongoDB support for Prisma ORM v7 is coming in the near future.** In the meantime, please use **Prisma ORM v6.19** (the latest v6 release) when working with MongoDB.
18+
19+
This guide uses Prisma ORM v6.19 to ensure full compatibility with MongoDB.
1820

1921
:::
2022

2123
## Prerequisites
2224

23-
<Prerequisites />
24-
25-
You also need:
26-
25+
- Node.js installed in your system [with the supported version](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-6#minimum-supported-nodejs-versions)
2726
- A [MongoDB](https://www.mongodb.com/) database accessible via connection string
2827

2928
## 1. Create a new project
@@ -35,10 +34,18 @@ You also need:
3534
Install the packages needed for this quickstart:
3635

3736
```terminal
38-
npm install prisma @types/node --save-dev
39-
npm install @prisma/client dotenv
37+
npm install prisma@6.19 @types/node --save-dev
38+
npm install @prisma/client@6.19 dotenv
4039
```
4140

41+
:::info[Why Prisma v6.19?]
42+
43+
This is the latest stable version of Prisma ORM v6 that fully supports MongoDB. MongoDB support for Prisma ORM v7 is coming soon.
44+
45+
You can also install `prisma@6` and `@prisma/client@6` to automatically get the latest v6 release.
46+
47+
:::
48+
4249
Here's what each package does:
4350

4451
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db push`, and `prisma generate`
@@ -94,11 +101,16 @@ npx prisma init --datasource-provider mongodb --output ../generated/prisma
94101

95102
This command does a few things:
96103

97-
- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
104+
- Creates a `prisma/` directory with a `schema.prisma` file for your database connection and schema models
98105
- Creates a `.env` file in the root directory for environment variables
99-
- Generates the Prisma Client in the `generated/prisma/` directory
100106
- Creates a `prisma.config.ts` file for Prisma configuration
101107

108+
:::note
109+
110+
Prisma Client will be generated in the `generated/prisma/` directory when you run `npx prisma generate` later in this guide.
111+
112+
:::
113+
102114
The generated `prisma.config.ts` file looks like this:
103115

104116
```typescript file=prisma.config.ts
@@ -156,7 +168,11 @@ Update your `.env` file with your MongoDB connection string:
156168
DATABASE_URL="mongodb+srv://username:password@cluster.mongodb.net/mydb"
157169
```
158170

159-
Replace with your actual MongoDB connection string.
171+
:::tip
172+
173+
Replace `username`, `password`, `cluster`, and `mydb` with your actual MongoDB credentials and database name. You can get your connection string from [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) or your MongoDB deployment.
174+
175+
:::
160176

161177
## 5. Define your data model
162178

@@ -194,19 +210,21 @@ model Post {
194210

195211
## 6. Push your schema to MongoDB
196212

197-
Since MongoDB doesn't use migrations, push your schema directly:
213+
MongoDB doesn't support migrations like relational databases. Instead, use `db push` to sync your schema:
198214

199215
```terminal
200216
npx prisma db push
201217
```
202218

203-
This command creates the collections based on your schema.
219+
This command:
220+
- Creates the collections in MongoDB based on your schema
221+
- Automatically generates Prisma Client
204222

205-
Now run the following command to generate the Prisma Client:
223+
:::info
206224

207-
```terminal
208-
npx prisma generate
209-
```
225+
Unlike relational databases, MongoDB uses a flexible schema. The `db push` command ensures your Prisma schema is reflected in your database without creating migration files.
226+
227+
:::
210228

211229
## 7. Instantiate Prisma Client
212230

content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import NextSteps from '../../_components/_next-steps.mdx'
1111

1212
[MongoDB](https://www.mongodb.com/) is a popular document-based NoSQL database known for its flexibility, scalability, and developer-friendly features. In this guide, you will learn how to add Prisma ORM to an existing TypeScript project, connect it to MongoDB, introspect your existing database schema, and start querying with type-safe Prisma Client.
1313

14+
:::warning[MongoDB support for Prisma ORM v7]
15+
16+
**MongoDB support for Prisma ORM v7 is coming in the near future.** In the meantime, please use **Prisma ORM v6.19** (the latest v6 release) when working with MongoDB.
17+
18+
This guide uses Prisma ORM v6.19 to ensure full compatibility with MongoDB.
19+
20+
:::
21+
1422
:::tip
1523

1624
If you're migrating to Prisma ORM from Mongoose, see our [Migrate from Mongoose guide](/guides/migrate-from-mongoose).
@@ -21,7 +29,7 @@ If you're migrating to Prisma ORM from Mongoose, see our [Migrate from Mongoose
2129

2230
In order to successfully complete this guide, you need:
2331

24-
- [Node.js](https://nodejs.org/en/) installed on your machine (see [system requirements](/orm/reference/system-requirements) for officially supported versions)
32+
- [Node.js](https://nodejs.org/en/) installed on your machine (see [system requirements](/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-6#minimum-supported-nodejs-versions) for officially supported versions)
2533
- An existing TypeScript project with a `package.json` file
2634
- Access to a MongoDB 4.2+ server with a replica set deployment. We recommend using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas).
2735

@@ -44,8 +52,8 @@ If your project contains multiple directories with `package.json` files (e.g., `
4452
Navigate to your existing project directory and install the required dependencies:
4553

4654
```terminal
47-
npm install prisma @types/node --save-dev
48-
npm install @prisma/client dotenv
55+
npm install prisma@6.19 @types/node --save-dev
56+
npm install @prisma/client@6.19 dotenv
4957
```
5058

5159
Here's what each package does:
@@ -54,9 +62,11 @@ Here's what each package does:
5462
- **`@prisma/client`** - The Prisma Client library for querying your database
5563
- **`dotenv`** - Loads environment variables from your `.env` file
5664

57-
:::info
65+
:::info[Why Prisma v6.19?]
66+
67+
This is the latest stable version of Prisma ORM v6 that fully supports MongoDB. MongoDB support for Prisma ORM v7 is coming soon.
5868

59-
MongoDB does not require a driver adapter like relational databases. Prisma Client connects directly to MongoDB.
69+
You can also install `prisma@6` and `@prisma/client@6` to automatically get the latest v6 release.
6070

6171
:::
6272

@@ -121,6 +131,7 @@ generator client {
121131
122132
datasource db {
123133
provider = "mongodb"
134+
url = env("DATABASE_URL")
124135
}
125136
```
126137

@@ -138,23 +149,23 @@ For MongoDB Atlas, the connection URL format is:
138149
mongodb+srv://USERNAME:PASSWORD@CLUSTER.mongodb.net/DATABASE
139150
```
140151

141-
The [format of the connection URL](/orm/reference/connection-urls) for MongoDB looks as follows (the parts spelled all-uppercased are _placeholders_ for your specific connection details):
152+
Self-hosted MongoDB connection URL format:
142153

143154
```
144155
mongodb://USERNAME:PASSWORD@HOST:PORT/DATABASE
145156
```
146157

147-
Here's a short explanation of each component:
158+
Connection URL components:
148159

149-
- **`USERNAME`**: The name of your database user
150-
- **`PASSWORD`**: The password for your database user
151-
- **`HOST`**: The host where a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod) (or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos)) instance is running
152-
- **`PORT`**: The port where your database server is running (typically `27017` for MongoDB)
153-
- **`DATABASE`**: The name of the database
160+
- **`USERNAME`**: Your database user name
161+
- **`PASSWORD`**: Your database user password
162+
- **`HOST`**: The host where [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos) is running
163+
- **`PORT`**: The port where your database server is running (typically `27017`)
164+
- **`DATABASE`**: The name of your database
154165

155166
:::tip
156167

157-
If you're using MongoDB Atlas, you need to manually append the database name to the connection URL because the environment link from MongoDB Atlas doesn't contain it.
168+
For MongoDB Atlas, you can manually append the database name to the connection URL, as Atlas doesn't include it by default.
158169

159170
:::
160171

@@ -176,15 +187,20 @@ Run the following command to introspect your existing database:
176187
npx prisma db pull
177188
```
178189

179-
This command reads the `DATABASE_URL` environment variable, connects to your database, and introspects the database schema. Prisma ORM introspects a MongoDB schema by sampling the data stored in the database and inferring the schema.
190+
This command:
191+
- Reads the `DATABASE_URL` from your `.env` file
192+
- Connects to your MongoDB database
193+
- Samples documents in your collections to infer the schema
194+
- Generates Prisma models in your `schema.prisma` file
180195

181196
![Introspect your database with Prisma ORM](/img/getting-started/prisma-db-pull-generate-schema.png)
182197

183-
After introspection, your Prisma schema will contain models that represent your existing MongoDB collections.
184-
185198
:::info
186199

187-
MongoDB introspection works by sampling documents in your collections. You may need to manually add relation fields using the `@relation` attribute to enable relational queries.
200+
**MongoDB introspection limitations:** Prisma introspects MongoDB by sampling documents. You may need to manually:
201+
- Add relation fields using the `@relation` attribute
202+
- Adjust field types if the sampling didn't capture all variations
203+
- Add indexes and constraints not detected during introspection
188204

189205
:::
190206

@@ -244,11 +260,11 @@ npx tsx script.ts
244260

245261
## 8. Evolve your schema
246262

247-
MongoDB does not use migrations. To make changes to your database schema:
263+
MongoDB doesn't support migrations like relational databases. Instead, use `db push` to sync schema changes:
248264

249265
### 8.1. Update your Prisma schema file
250266

251-
Update your Prisma schema file to reflect the changes you want to make to your database schema. For example, add a new model:
267+
Modify your Prisma schema file with the changes you want. For example, add a new model:
252268

253269
```prisma file=prisma/schema.prisma
254270
// add-start
@@ -276,19 +292,19 @@ In MongoDB, the `id` field is mapped to `_id` and uses `@db.ObjectId` type. Rela
276292

277293
:::
278294

279-
### 8.2. Push the changes to your database:
295+
### 8.2. Push the changes to your database
280296

281297
```terminal
282298
npx prisma db push
283299
```
284300

285-
This command will:
286-
- Apply the schema changes to your MongoDB database
287-
- Regenerate Prisma Client
301+
This command:
302+
- Applies schema changes to your MongoDB database
303+
- Automatically regenerates Prisma Client
288304

289-
:::info
305+
:::info[Why `db push` instead of migrations?]
290306

291-
Prisma Migrate is not supported for MongoDB. Use `prisma db push` to sync your schema changes.
307+
MongoDB uses a flexible schema model. Prisma Migrate (which creates migration files) is not supported for MongoDB. Always use `prisma db push` to sync your schema changes.
292308

293309
:::
294310

content/100-getting-started/03-prisma-postgres/100-from-the-cli.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Initialize a TypeScript project and add the Prisma CLI as a development dependen
129129

130130
```terminal
131131
npm init -y
132-
npm install typescript tsx @types/node --save-dev
132+
npm install typescript tsx @types/node @types/pg --save-dev
133133
```
134134

135135
This creates a `package.json` file with an initial setup for your TypeScript app.
@@ -173,14 +173,16 @@ Install the required dependencies to use Prisma Postgres:
173173

174174
```terminal
175175
npm install prisma --save-dev
176-
npm install @prisma/client @prisma/adapter-pg dotenv
176+
npm install @prisma/client @prisma/adapter-pg pg dotenv
177177
```
178178

179179
Here's what each package does:
180180

181181
- **`prisma`** - The Prisma CLI for running commands like `prisma migrate` and `prisma generate`
182182
- **`@prisma/client`** - The Prisma Client library for querying your database
183183
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database
184+
- **`pg`** - The node-postgres database driver
185+
- **`@types/pg`** - TypeScript type definitions for node-postgres
184186
- **`dotenv`** - Loads environment variables from your `.env` file
185187

186188
### 2.4. Create prisma.config.ts

0 commit comments

Comments
 (0)