mongorepository

Generic implementation of the repository pattern for nodejs/mongodb

mongorepository

A node.js module that contains a generic implementation of the Repository Pattern for mongoDB.

The easiest way to install is through the Node Package Manager (NPM):

npm install mongorepository
//reference the repository object 
var Repository = require('mongoRepository').Repository;
 
//create an instance 
var catRepository = new Repository('username:password@localhost/dbname', 'cat');
 
var cat = {
  _id : 101,
  name: 'trevor'
}
 
//add cat 
catRepository.add(cat);
 
//get cat by id 
catRepository.get(101, function(returnedCat){
    console.log(returnedCat);
});
 
//find cat 
query = {name: 'trevor'}
catRepository.find(query, function(results){
  console.log(results);
});
 
//update cat 
cat.age = 4;
catRepository.update(query, cat);
 
//delete cat 
catRepository.remove(query,function(){
    console.log("Removed ",cat);
});