Mongo Decorators and Modules
Description
This is a MayaJS library that deals with Mongodb drivers. It uses mongoose
to connect to any mongodb database. It also use mongoose Schema and Model for its model creation.
Decorators
Models
Creates a model intance based on the name passed on the parameter.
MayaJS collect and store all the models defined on the @Controller
decorators to a single object. Everytime the @Models
decorator is attached to a variable it replace its value with a model instance. This model instance is based on mongoose model. All of mongoose functionality is available for this model instance.
Pseudo Code
@Models(model_name:string) varaiable_name;
Sample Code
@Models("sample") model;
Modules
Mongo
A wrapper for mongoose that MayaJS use to connect to MongoDB.
Mongo accepts an object settings that will set the connection for MongoDB. MayaJS will automatically connect to the specified settings whenever the server starts. It will also set the models using the models function. It typically used inside the @App
decorator on the options paramater.
Options
{
connectionString: string;
options?: ConnectionOptions;
}
NOTE: See full documentation of ConnectionOptions here.
Sample Code
@App({
database: Mongo({
connectionString: process.env.MONGO_CONNECTION_URL || "your-connection-string-here",
options: { useCreateIndex: true, useNewUrlParser: true, useFindAndModify: false },
}),
})
export class AppModule {}