Overview
The schema configuration file (schema.yml) defines the structure of your collections including field types, validation constraints, indexes, access control fields, and versioning settings.
Configuration Structure
Global Settings
Define default behaviors applied across all collections.Default field name used for tenant isolation across all collections.Example:
tenant_idDefault field name used for owner-based access control.Example:
owner_idAutomatically manage
created_at and updated_at fields for all collections.Default ID type for documents. Options:
objectId, uuid, string.Example
Collection Definition
Define the structure for each collection.Field Types
Permission Mongo supports the following field types:The data type of the field.Supported types:
string- Text datanumber- Floating point numbersinteger- Whole numbersboolean- True/false valuesdate- Date and time valuesobjectId- MongoDB ObjectIDuuid- UUID stringsarray- Array of values (requiresitemsconfig)object- Nested object (requirespropertiesconfig)any- Any data type (no validation)
Field Options
Basic Constraints
Whether the field is required on document creation.
Default value when field is not provided. Supports static values and expressions.
Field cannot be modified after document creation.
Automatically generate value on document creation (e.g., timestamps, IDs).
Automatically update value on document modification (e.g.,
updated_at).String Constraints
Minimum string length.
Maximum string length.
Regular expression pattern the string must match.
Predefined format validation. Options:
email, url, date, time, datetime.Numeric Constraints
Minimum numeric value.
Maximum numeric value.
Enum Values
List of allowed values for the field.
References
Name of the collection this field references (foreign key).
Array Fields
Define array fields with item type validation:Object Fields
Define nested object structures:Computed Fields
Define fields calculated from other field values:MongoDB aggregation expression to compute the field value.
Whether to persist the computed value in the database.
List of fields that trigger recomputation when changed.
Example
Indexes
Define indexes for query optimization and uniqueness constraints.List of field names included in the index.
Sort order for each field:
1 for ascending, -1 for descending. Defaults to 1 for all fields.Whether the index enforces uniqueness.
Whether the index is sparse (only indexes documents containing the indexed fields).
Custom name for the index.
Examples
Access Control
Define fields used for tenant isolation and ownership.Field name used for multi-tenant isolation. Overrides global
default_tenant_field.Field name used for owner-based access control. Overrides global
default_owner_field.Example
Versioning
Configure document versioning at the collection level.Enable version tracking for documents in this collection.
Version storage mode:
full- Store complete document snapshotsdiff- Store only changed fields
Maximum number of versions to retain per document.
Number of days to retain old versions.
Example
Hierarchy Configuration
Configure user hierarchy for permission inheritance.Field containing the user ID for hierarchy lookups.
Field containing the manager’s user ID.
Example
Complete Example
Environment Variables
Schema configuration supports environment variable substitution:Loading Schema Configuration
Load the schema configuration at server startup:PM_SCHEMA environment variable: