Appearance
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"
}
}| Command | What it does |
|---|---|
npm run db:generate | Regenerates 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:push | Applies the current schema to the database (collections / fields) without migration history files—typical for MongoDB + Prisma during development. |
npm run db:studio | Opens Prisma Studio in the browser to browse and edit documents when debugging. |
Note: With MongoDB, teams often rely on
db pushinstead of SQL-stylemigrateworkflows. Your project may also define extra scripts (for example seeding or introspection)—checkpackage.jsonfor the full list.
Typical workflow
- Define models — Edit
prisma/schema.prisma. - Sync the database — Run
npm run db:pushso MongoDB matches your schema. - Refresh the client — Run
npm run db:generateafter schema changes (some setups run this automatically). - Develop — Start the app with
npm run dev. - Optional — Use
npm run db:studioto inspect or tweak data.