Skip to content

MongoDB & Prisma Setup

NexusOrbit uses MongoDB as its primary database, managed through Prisma. This guide shows how to configure your connection string and use Prisma for local development and production.

1. Configure your MongoDB connection (.env)

Set your MongoDB connection string in a .env file at the root of the project (use .env.example as a template if your repo ships one).

bash
# MongoDB Atlas (recommended for hosted DB)
DATABASE_URL="mongodb+srv://[USER]:[PASSWORD]@[CLUSTER_URL]/[DATABASE]?retryWrites=true&w=majority"

# Local MongoDB (optional)
# DATABASE_URL="mongodb://localhost:27017/[DATABASE]"
  • Replace [USER], [PASSWORD], [CLUSTER_URL], and [DATABASE] with your Atlas user, password, cluster host, and database name.
  • For a local instance, uncomment the second line and point it at your local server and database name.

Prisma reads DATABASE_URL for schema sync (db push), client generation, and all runtime queries.

2. Prisma scripts (package.json)

Your app should include scripts similar to the following for day-to-day database work:

json
{
  "scripts": {
    "db:studio": "prisma studio",
    "db:push": "prisma db push",
    "db:generate": "prisma generate"
  }
}
CommandWhat it does
npm run db:generateRegenerates the Prisma Client from prisma/schema.prisma. Run this after you change models so your app’s types and query API stay in sync.
npm run db:pushApplies the current schema to the database (collections / fields) without migration history files—typical for MongoDB + Prisma during development.
npm run db:studioOpens Prisma Studio in the browser to browse and edit documents when debugging.

Note: With MongoDB, teams often rely on db push instead of SQL-style migrate workflows. Your project may also define extra scripts (for example seeding or introspection)—check package.json for the full list.

Typical workflow

  1. Define models — Edit prisma/schema.prisma.
  2. Sync the database — Run npm run db:push so MongoDB matches your schema.
  3. Refresh the client — Run npm run db:generate after schema changes (some setups run this automatically).
  4. Develop — Start the app with npm run dev.
  5. Optional — Use npm run db:studio to inspect or tweak data.

Built with Nexus Orbit