Performance: Schema definition
MEDIUM IMPACT
Schema definitions impact server response time and data validation speed, which indirectly affect frontend load and interaction times.
import { Schema } from 'mongoose'; const UserSchema = new Schema({ name: { type: String, required: true }, age: { type: Number, min: 0, max: 120 }, address: { street: { type: String }, city: { type: String }, zip: { type: String } } });
import { Schema } from 'mongoose'; const UserSchema = new Schema({ name: { type: String, required: true }, age: { type: Number }, address: { type: Object }, extra: { type: Schema.Types.Mixed } });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Loose schema with Mixed/Object types | N/A (server-side) | N/A | N/A | [X] Bad |
| Strict schema with explicit nested types | N/A (server-side) | N/A | N/A | [OK] Good |