Skip to content

@iamcalegari/mongoat / Schema

Function: Schema()

Schema(collectionName?): (value, context) => void

Defined in: src/schema/decorators.ts:260

Class decorator that closes a decorated schema class. Runs AFTER all field decorators (a TC39 spec guarantee), so it sees the fully populated metadata.

The optional collectionName becomes the default collection name for models created from this class (the model config can still override it).

Throws MongoatValidationError with code INVALID_DECORATED_CLASS when the class has no decorated field — an empty schema is always a mistake.

Parameters

collectionName?

string

Returns

(value, context) => void

Example

typescript
@Schema('users')
class UserSchema {
  @Prop({ bsonType: 'string' })
  username!: string;
}