
prisma-database-setup-mongodb
✓ Official★ 8by prisma · part of prisma/cursor-plugin
MongoDB Setup. Reference when using this Prisma feature.
MongoDB Setup. Reference when using this Prisma feature.
Inspect the full instructions your agent will receiveExpandCollapse
This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.
by prisma
MongoDB Setup. Reference when using this Prisma feature.
npx skills add https://github.com/prisma/cursor-plugin --skill prisma-database-setup-mongodb
Download ZIPGitHub8
2. Environment Variable
In .env:
DATABASE_URL="mongodb+srv://user:[email protected]/mydb?retryWrites=true&w=majority"
Migrations vs Introspection
-
No Migrations: MongoDB is schema-less.
prisma migratecommands do not work. -
db push: Use
prisma db pushto sync indexes and constraints. -
db pull: Use
prisma db pullto generate schema from existing data (sampling).
npx skills add https://github.com/prisma/cursor-plugin --skill prisma-database-setup-mongodbRun this in your project — your agent picks the skill up automatically.
MongoDB Setup
⚠️ WARNING: MongoDB is NOT supported in Prisma ORM v7.
Support for MongoDB is planned for a future v7 release. If you need MongoDB, you must use Prisma ORM v6.
Prerequisites
-
MongoDB 4.2+
-
Replica Set configured (required for transactions)
-
Prisma ORM v6.x
1. Schema Configuration (v6)
In prisma/schema.prisma:
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
ID Field Requirement
MongoDB models must have a mapped _id field using @id and @map("_id"), usually of type String with auto() and db.ObjectId.
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String?
}
Relations
Relations in MongoDB expect IDs to be db.ObjectId type.
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
}
Common Issues
"Transactions not supported"
Ensure your MongoDB instance is a Replica Set. Standalone instances do not support transactions. Atlas clusters are replica sets by default.
"Invalid ObjectID"
Ensure fields referencing IDs are decorated with @db.ObjectId if the target is an ObjectID.