Skip to content

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

PropertyModifierTypeDefault valueDescription
_modelprivatenull | Model<any, { }, { }>nullOptional mongoose model for this collection
collectionreadonlystringundefinedThe name of the collection
databasereadonlystringundefinedThe name of the database
permissionsreadonlyPermission[]undefinedList of permissions for the collection
schemareadonlySchema<any>undefinedMongoose schema definition
triggers?readonlyDatabaseTrigger[]undefinedOptional 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

ParameterTypeDescription
modelModel<any>The mongoose model

Returns

void