Builder's DayOctober 26 · SFGet tickets

Prisma 8 extension

MongoDB

MongoDB support for Prisma ORM: config, runtime, contract authoring, BSON values, and migrations in one package.

By PrismaMongoDB

What it does

The one package a MongoDB application installs. It provides defineConfig, the mongo() runtime with the ORM client and the typed pipeline builder, contract authoring, control-plane access, and BSON value constructors under @prisma/orm-mongo/bson.

Configure the database

prisma.config.ts
import { definePrismaConfig } from 'prisma/config';
import { defineConfig as ormConfig } from '@prisma/orm-mongo/config';

export default definePrismaConfig({
  orm: ormConfig({
    contract: './src/prisma/contract.prisma',
    db: {
      connection: process.env['MONGODB_URL']!,
    },
  }),
});

Create the client

src/prisma/db.ts
import mongo from '@prisma/orm-mongo/runtime';
import type { Contract } from './contract.d';
import contractJson from './contract.json' with { type: 'json' };

export const db = mongo<Contract>({
  contractJson,
  url: process.env['MONGODB_URL']!,
  dbName: 'app',
});