Skip to content
This repository has been archived by the owner on Mar 17, 2018. It is now read-only.

blugavere/mongodb-repository

Repository files navigation

MongoDB Repository

NPM versiondependencies Status Coverage StatusNPM DownloadsBuild StatusPatreon

This has been moved to a monorepo, https://github.com/blugavere/node-repositories

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

Releases

No releases published

Packages

No packages published