defineCollection(
options):CollectionDefinition&object
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[]
})
]
// Access the model directly:
const userCollection = defineCollection({...});
const UserModel = userCollection.model;
const users = await UserModel.find();Parameters
| Parameter | Type | Description |
|---|---|---|
options | { collection: string; database: string; mongoOption: MongoOption; permissions: Permission[]; schema: Schema<any>; triggers: DatabaseTrigger[]; } | The options for the collection |
options.collection | string | The name of the collection to be configured |
options.database | string | The name of the database where the collection resides |
options.mongoOption? | MongoOption | Optional MongoDB connection options. If not provided, will use config.mongo if available. This is used to pre-create the model before server startup. |
options.permissions | Permission[] | List of permissions controlling access to the collection |
options.schema | Schema<any> | Mongoose 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 & object
A CollectionDefinition instance with a model property that returns the mongoose model