Prisma v7-uses both MongoDB and PostgreSQL with separate Prisma schemas #29681
Replies: 3 comments
|
Your question is valid and the answer is confirmed by Prisma's official documentation and engineering team. Here is the precise, accurate picture. Current status — verified factsPrisma ORM v7 does not yet support MongoDB. Prisma's official documentation explicitly states: "If you are using MongoDB, please note that Prisma ORM v7 does not yet support MongoDB. You should continue using Prisma ORM v6 for now. Support for MongoDB is coming soon in v7." The currently recommended version for MongoDB is Prisma ORM v6.19, the latest v6 stable release. MongoDB didn't make the v7 release because the architectural changes in Prisma 7 required deep rework at the query layer, and SQL databases were prioritized. This isn't a permanent statement about MongoDB — bringing MongoDB support back is described as a priority, but it isn't available today. Direct answer to your questionYour current approach — using Your second option — mixing v6.4.1 for MongoDB with Prisma ORM v7 for PostgreSQL in the same project — is the correct recommended approach. Here is why and exactly how to do it safely. Recommended production setup — two separate clients, different versionsThis is a supported pattern. Prisma's multiple schema / multiple client support means you can have both installed in the same project with isolated generated outputs. Installation# Install v7 for PostgreSQL
npm install prisma@7 @prisma/client@7 --save-dev
# Install v6 for MongoDB (as a scoped alias)
npm install prisma6@npm:prisma@6.19 prisma-client6@npm:@prisma/client@6.19 --save-devDirectory structurePostgreSQL schema (v7 syntax)// prisma/postgres/schema.prisma
generator client {
provider = "prisma-client" // v7 uses "prisma-client", not "prisma-client-js"
output = "../../generated/postgres"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_DATABASE_URL")
}
model Order {
id String @id @default(uuid())
userId String
total Float
createdAt DateTime @default(now())
}// prisma/postgres/prisma.config.ts — required in v7
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/postgres/schema.prisma",
migrations: {
path: "prisma/postgres/migrations",
},
datasource: {
url: env("POSTGRES_DATABASE_URL"),
},
});MongoDB schema (v6 syntax)// prisma/mongo/schema.prisma
generator client {
provider = "prisma-client-js" // v6 uses "prisma-client-js"
output = "../../generated/mongo"
}
datasource db {
provider = "mongodb"
url = env("MONGO_DATABASE_URL")
}
model Product {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
description String?
price Float
stock Int
}Importing in your application// Import PostgreSQL client (v7)
import { PrismaClient as PostgresClient } from '../generated/postgres';
import { PrismaPg } from '@prisma/adapter-pg';
const adapter = new PrismaPg({ connectionString: process.env.POSTGRES_DATABASE_URL });
const postgresClient = new PostgresClient({ adapter }); // v7 requires adapter
// Import MongoDB client (v6)
import { PrismaClient as MongoClient } from '../generated/mongo';
const mongoClient = new MongoClient();package.json scripts{
"scripts": {
"db:generate:postgres": "prisma generate --config prisma/postgres/prisma.config.ts",
"db:generate:mongo": "prisma6 generate --schema prisma/mongo/schema.prisma",
"db:migrate:postgres": "prisma migrate deploy --config prisma/postgres/prisma.config.ts",
"db:push:mongo": "prisma6 db push --schema prisma/mongo/schema.prisma"
}
}Key differences between v6 and v7 you must account for
Important caveats for your e-commerce production app1. v7 requires a driver adapter for PostgreSQL — you cannot instantiate import { PrismaPg } from '@prisma/adapter-pg';
const adapter = new PrismaPg({ connectionString: process.env.POSTGRES_DATABASE_URL });
const prisma = new PrismaClient({ adapter });2. Remove any // v6 (MongoDB) — $use still works
mongoClient.$use(async (params, next) => { ... });
// v7 (PostgreSQL) — must use $extends
const postgresClient = new PostgresClient({ adapter }).$extends({
query: {
$allModels: {
async $allOperations({ operation, model, args, query }) {
// your middleware logic
return query(args);
}
}
}
});3. Auto-seeding is removed in v7 — if you relied on 4. When Prisma v7 adds MongoDB support, a second migration from v6 to v7 will be needed for the MongoDB client (ESM-only, driver adapters mandatory, new generator syntax). Design your MongoDB service layer to make this future migration straightforward — avoid tight coupling between your MongoDB and PostgreSQL service layers.** Tracking MongoDB v7 supportThere is a roadmap for MongoDB support laid out in Prisma discussion #29296. The recommended path is to stick to v6 as the stable production path until an official Release Candidate (RC) explicitly mentions MongoDB parity for v7. You can track the specific v7 milestone or Hope this helps — if it answers your question, would you mind clicking "Mark as answer" so others searching for the same thing can find it quickly? |
|
The two-versions-in-one-project approach needs a bit more than installing both, and it's worth testing before you commit to it for production. Installing them one after the other doesn't give you two clients — npm has a single name per package at the top level, so the second install replaces the first: The MongoDB client is simply gone at that point. npm aliasing is the usual next idea, and it does put both on disk: But it doesn't actually solve it, because the generated client doesn't import through the alias. Every generated file uses the bare specifier: // generated/prisma/client.ts
import * as runtime from "@prisma/client/runtime/client"Same in What does work is giving each database its own resolution root, e.g. workspaces: Each package's generated client then resolves the bare specifier by walking up from its own directory and lands on the right major. Worth noting npm decides which one gets hoisted to the root, so don't rely on a particular layout — if you want that deterministic, pnpm isolates by default (I only tested npm here, so treat that as a suggestion rather than a verified result). One other thing that may change your plan: both CLIs now scaffold the same generator. generator client {
provider = "prisma-client"
output = "../generated/prisma"
}so neither version generates into For what it's worth, splitting the two databases into separate packages is likely worth doing regardless of Prisma versions. You get one client per package, no ambiguity about which schema a query belongs to, and when MongoDB support does land in v7 you upgrade one package instead of untangling a shared |
Recommended Approach: Stay on Unified
|
Uh oh!
There was an error while loading. Please reload this page.
Question
Hi! I have a project that uses both MongoDB and PostgreSQL with separate Prisma schemas and generated clients.
For now I'm using @prisma/client v6.4.1 for both databases:
@prisma/clientv6.4.1@prisma/clientv6.4.1The reason is that Prisma ORM v7 does not yet support MongoDB.
My question is: Is this the recommended approach for a production e-commerce application that uses both MongoDB and PostgreSQL?
Or would it be better to use:
within the same project until MongoDB support is added to v7?
I'd appreciate any recommendations or best practices from the Prisma team. Thanks!
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
// Add your schema.prisma// Add any relevant Prisma Client queries hereOS:
Database:
Node.js version:
Run
prisma -vto see your Prisma version and paste itAll reactions