Skip to content

Database Setup

Fresh

Source: shipfa.st/docs/features/database

Procedure

  1. Create a new project and deploy a cluster on MongoDB Atlas

TIP

Run a local database for dev -- works offline and is faster.

  1. In MongoDB Atlas, click Network Access > + Add IP Address. Enter 0.0.0.0/0 to allow connections from anywhere (dev + production).

  2. Add your connection string to MONGODB_URI in .env.local.

Mongoose (Optional)

Mongoose makes MongoDB easier with schema validation and plugins.

  • Models are in the /models folder
  • The toJSON plugin removes _id and __v from responses
  • Add private: true to any field to exclude it from API responses
javascript
// Example: email won't be sent to frontend
const UserSchema = new Schema({
  name: String,
  email: { type: String, private: true },
  hasAccess: { type: Boolean, default: false }
});

Verification Checklist

  • [ ] MongoDB Atlas cluster created
  • [ ] IP whitelist set to 0.0.0.0/0
  • [ ] MONGODB_URI added to .env.local
  • [ ] Can connect from localhost

See Also