Matt Mueller (Prisma Client PM)
mongoDb
preview feature flag:
prisma
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb"]
}
Then you'll have a new type
keyword in your Prisma Schema, for example:
prisma
model Order {
id String @id @default(auto()) @map("_id") @db.ObjectId
product Product @relation(fields: [productId], references: [id])
color Color
size Size
shippingAddress Address
billingAddress Address?
productId String @db.ObjectId
}
// New composite type!
type Address {
street String
city String
zip String
}
Once you run prisma generate
, you'll have a new type-safe API for working with these types.
For example, here's how you'd create a new Order with an embedded shipping address:
ts
const order = await prisma.order.create({
data: {
// Normal relation
product: { connect: { id: 'some-object-id' } },
color: 'Red',
size: 'Large',
// Composite type
shippingAddress: {
street: '1084 Candycane Lane',
city: 'Silverlake',
zip: '84323',
},
},
})
This is just the tip of the iceberg. Dive deeper in our documentation.
---
If you have any feedback for us, I'd love to jump on a call with you.
We're actively working towards getting MongoDB production ready, so now's the time to give this a try and share your thoughts!