0.1.6 • Published 7 years ago
inceptum-mongoose v0.1.6
Use mongoose in your inceptum project
install
$ yarn add inceptum-mongoose
Add mongoose development configuration
# config/default.yml
# ...
mongoose:
mongodbUri: mongodb://127.0.0.1:27017/testdb
connectionOptions:
autoIndex: false
# ...
also add production environment variables
# config/custom-environment-variables.yml
# ...
mongoose:
mongodbUri: MONGODB_URI
# ...
Enable the plugin
// src/index.ts
const app = new InceptumApp();
// ...
app.use(
// ...
new MongoosePlugin(),
// ...
);
Make your mongoose models work in typescript
// src/user/user.interface.ts
import { Document } from 'mongoose';
export interface User extends Document {
email: string,
password: string,
// ...
}
// src/user/user.model.ts
import { Document, Schema, Model, model } from 'mongoose';
import { User } from './user.interface';
const userSchema: Schema = new Schema(
{
email: String,
password: String,
// ...
},
);
export default model<User>('User', userSchema);