A class that represents a MongoDB collection configuration. Provides full support for schema validation, access control through permissions, and custom triggers for various database operations.
Deprecated
Use defineCollection instead.
Example
typescript
const userSchema = new Schema({
name: String,
email: String,
age: Number
});
const collection = new CollectionDefinition({
database: 'myapp',
collection: 'users',
schema: userSchema,
permissions: [
new Permission({
type: 'user_access',
read: true,
write: true
})
],
triggers: [
new DatabaseTrigger('insert-one', (data) => {
console.log('New user created:', data);
})
]
});Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
_model | private | null | Model<any, { }, { }> | null | Optional mongoose model for this collection |
collection | readonly | string | undefined | The name of the collection |
database | readonly | string | undefined | The name of the database |
permissions | readonly | Permission[] | undefined | List of permissions for the collection |
schema | readonly | Schema<any> | undefined | Mongoose schema definition |
triggers? | readonly | DatabaseTrigger[] | undefined | Optional database triggers |
Methods
getModel()
getModel():
null|Model<any, { }, { }>
Get the mongoose model for this collection
Returns
null | Model<any, { }, { }>
The mongoose model or null if not set
setModel()
setModel(
model):void
Set the mongoose model for this collection
Parameters
| Parameter | Type | Description |
|---|---|---|
model | Model<any> | The mongoose model |
Returns
void