Hey all, I just wanted to share that Embedded Docu...
# orm-help
m
Hey all, I just wanted to share that Embedded Document support for MongoDB is now in Preview! It's easy to get started. First, install the latest Prisma (3.10.0) and add the
mongoDb
preview feature flag:
Copy code
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:
Copy code
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:
Copy code
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!
prisma rainbow 2
mongodb 2
prisma cool 1