Skip to content

defineCollection(options): CollectionDefinition

To have define any collection in your database you haveto use below method in your db.[js|ts] file and export an array of CollectionDefinition instances.

Example

typescript
import { defineCollection } from '@modular-rest/server';

export default [
  defineCollection({
    database: 'users',
    collection: 'info',
    // schema: Schema,
    // permissions: Permission[]
    // trigger: DatabaseTrigger[]
  })
]

Parameters

ParameterTypeDescription
options{ collection: string; database: string; permissions: Permission[]; schema: Schema; triggers: DatabaseTrigger[]; }The options for the collection
options.collectionstringThe name of the collection to be configured
options.databasestringThe name of the database where the collection resides
options.permissionsPermission[]List of permissions controlling access to the collection
options.schemaSchemaMongoose schema definition for the collection See https://mongoosejs.com/docs/5.x/docs/guide.html
options.triggers?DatabaseTrigger[]Optional database triggers for custom operations

Returns

CollectionDefinition

A new instance of CollectionDefinition