Skip to content

Database Utilities

Contains utilities related to database operations.

Get Collection

getCollection<T>(db, collection): Model<T>

Function

Gets a Mongoose model for a specific collection getCollection

Example

typescript
const userModel = getCollection('myapp', 'users');
const users = await userModel.find();

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
dbstringDatabase name
collectionstringCollection name

Returns

Model<T>

Mongoose model for the collection

Throws

If the collection doesn't exist