Documentation Index
Fetch the complete documentation index at: https://www.esixorm.com/llms.txt
Use this file to discover all available pages before exploring further.
Defining Models
Models are the heart of Esix! They provide a beautiful, simple ActiveRecord-style implementation for working with your MongoDB collections. Each collection in your database has a corresponding model class that makes it easy to query, create, and update your data. Think of models as the bridge between your TypeScript code and your MongoDB collections. Let’s create your first model and see how simple it is!Creating a Basic Model
Here’s how you create a simple blog post model:BaseModel class, you automatically get access to all of Esix’s powerful features. Your model can now create and update documents and query your MongoDB collection.
Built-in Properties
Every Esix model automatically comes with some helpful built-in properties:id
Your model gets an id property that defaults to a MongoDB ObjectId. You can also provide your own custom ID if needed.
Timestamps
Two timestamp properties are automatically managed for you:createdAt- Set when the document is first createdupdatedAt- Updated every time you save or update the document
Collection Naming
Esix automatically determines which MongoDB collection to use based on your model’s class name. This follows our Convention over Configuration philosophy to keep things simple. Here’s how the naming works:| Model Class Name | Collection Name |
|---|---|
BlogPost | blog-posts |
User | users |
OrderItem | order-items |
Comment | comments |
- Converting from PascalCase to kebab-case (dashes)
- Making it plural
Relationships
Models can declare relationships to one another withhasMany, hasOne, and
belongsTo. These helpers are documented in detail in the
Relationships guide.