mongorepository

Generic implementation of the repository pattern for nodejs/mongodb

npm install mongorepository
14 downloads in the last week
67 downloads in the last month

mongorepository

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

Installation

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

npm install mongorepository

Usage

//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);
});
npm loves you