Chain .optional() to make a field nullable. The field can then be omitted or set to null.
Scalars are typically placed in __scalar/ directory to indicate they're embedded types, not standalone collections.
|
| fieldType | "property" | "hidden" | "resolve" | "property" | property: normal field, hidden: backend-only (not sent to frontend), resolve: computed field (not stored in DB). | |
| immutable | boolean | false | If true, field cannot be modified after document creation. Only set during create. | |
| min | number | - | Minimum value constraint for Int or Float fields. Validation runs on save. | |
| max | number | - | Maximum value constraint for Int or Float fields. Validation runs on save. | |
| minlength | number | - | Minimum string length constraint for String fields. | |
| maxlength | number | - | Maximum string length constraint for String fields. | |
| enum | EnumClass | - | Restrict field values to enum values. Typically used with enumOf() defined classes. | |
| select | boolean | true | If false, field is excluded from default queries. Use for sensitive or large fields. | |
| accumulate | object | - | MongoDB aggregation expression for Insight fields. Calculates statistics across matched documents. | |
| example | any | - | Example value for API documentation generation (Swagger/OpenAPI). | |
| of | Type | - | Value type for Map fields. The key is always string, value type is specified by 'of'. | |
| validate | (value, model) => boolean | - | Custom validation function. Receives the field value and full model, returns boolean. | |
| text | "search" | "filter" | - | Enable text indexing for full-text search (search) or filtering (filter) capabilities. | |
| meta | object | - | Custom metadata object for additional field information used by UI components or plugins. | |
Default value when no value is provided. Can be a static value or a function for dynamic defaults.
If true, the field can be null or omitted. Equivalent to using .optional() chain method.
Reference collection name for ID fields. Used for MongoDB population.
Dynamic reference path - uses another field's value to determine the referenced collection.
Type of reference relationship. Affects how population and cascading operations work.
Preset type that applies default validation and example values for common patterns.
property: normal field, hidden: backend-only (not sent to frontend), resolve: computed field (not stored in DB).
If true, field cannot be modified after document creation. Only set during create.
Minimum value constraint for Int or Float fields. Validation runs on save.
Maximum value constraint for Int or Float fields. Validation runs on save.
Minimum string length constraint for String fields.
Maximum string length constraint for String fields.
Restrict field values to enum values. Typically used with enumOf() defined classes.
If false, field is excluded from default queries. Use for sensitive or large fields.
MongoDB aggregation expression for Insight fields. Calculates statistics across matched documents.
Example value for API documentation generation (Swagger/OpenAPI).
Value type for Map fields. The key is always string, value type is specified by 'of'.
Custom validation function. Receives the field value and full model, returns boolean.
Enable text indexing for full-text search (search) or filtering (filter) capabilities.
Custom metadata object for additional field information used by UI components or plugins.
| field | Description |
|---|---|
| property | Normal field - stored in DB, sent to frontend |
| hidden | Backend only - stored in DB but never sent to frontend (e.g., OTP codes) |
| resolve | Virtual field - computed on query, not stored in DB (e.g., view count from other collection) |
Normal field - stored in DB, sent to frontend
Backend only - stored in DB but never sent to frontend (e.g., OTP codes)
Virtual field - computed on query, not stored in DB (e.g., view count from other collection)
| field | Description |
|---|---|
| parent | This document belongs to the referenced document |
| child | Referenced document belongs to this document |
| relation | Many-to-many relationship without ownership |
This document belongs to the referenced document
Referenced document belongs to this document
Many-to-many relationship without ownership
Always use direct file imports for other constants to avoid circular references. Never import from barrel files.