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

PropertyModifierTypeDescription
collectionreadonlystringThe name of the collection
databasereadonlystringThe name of the database
permissionsreadonlyPermission[]List of permissions for the collection
schemareadonlySchemaMongoose schema definition
triggers?readonlyDatabaseTrigger[]Optional database triggers