mongodb-repository
v0.0.0
Published
Generic IRepository implementation for MongoDB
Downloads
7
Maintainers
Readme
MongoDB Repository
Installation
$ npm install --save mongodb-repository
Usage
'use strict'
const MongoRepository = require('mongodb-repository');
class CatRepository extends MongoRepository {
constructor(db, modelName) {
super(db, modelName);
}
}
// or if you dont need custom functionality
const repo = new MongoRepository(db, modelName);
Getting Started
'use strict';
const MongoClient = require('mongodb').MongoClient;
// configure a collection name
const collection = 'cats';
const MongoRepository = require('mongodb-repository');
let repo;
// connect to mongodb
MongoClient.connect('mongodb://localhost', (err, db) => {
// construct a repo
repo = new MongoRepository(db, collection);
repo.add({name:'Fido'}, (err, data) => {
console.log(data);
repo.disconnect();
});
}
License
MIT © Ben Lugavere