mongoose-repository
v0.2.0
Published
Generic IRepository implementation for MongoDB using Mongoose
Downloads
16
Maintainers
Readme
Mongoose Repository
Installation
$ npm install --save mongoose-repository
Usage
'use strict'
const mongoose = require('mongoose');
const MongooseRepository = require('mongoose-repository');
class CatRepository extends MongooseRepository {
constructor(mongoose, modelName) {
super(mongoose, modelName);
}
}
// or if you dont need custom functionality
const repo = new MongooseRepository(mongoose, modelName);
Getting Started
'use strict';
const mongoose = require('mongoose');
const modelName = 'cats';
// configure a schema somewhere
const schema = new mongoose.Schema({
name: { type: String }
});
// register it to mongoose
mongoose.model(modelName, schema);
// connect to mongodb
mongoose.connect('mongodb://localhost');
const MongooseRepository = require('mongoose-repository');
const repo = new MongooseRepository(mongoose, modelName);
// default json format
const cat = { name : 'Fido' };
repo.add(cat, (err, data) => {
console.log(data);
repo.disconnect();
});
Contributing
Roadmap
- Pre / Post fetch hooks
- Mixin Apis
- Deprecate usage of mongoose global (unneccesary)
License
MIT © Ben Lugavere