Skip to main content
Orionjs schemas seamlessly integrate with MongoDB through the @orion-js/mongodb package, providing type-safe database operations.

Defining Collections

To create a MongoDB collection with schema validation:

TypedId Support

Orionjs MongoDB has built-in support for typed IDs with automatic prefixing:

Collection Operations

All MongoDB collection operations are typed based on your schema:

Schema Validation in MongoDB

When you create a collection with a schema, Orionjs automatically:
  1. Creates a MongoDB validation schema based on your Orionjs schema
  2. Applies validation on all insert and update operations
  3. Enforces types and constraints defined in your schema

Repository Pattern

For better organization, you can create a repository class for each collection:

Index Management

You can define indices for your collections: