mongodb-repository
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.0 • Public • Published

    MongoDB Repository

    NPM versiondependencies Status Coverage StatusNPM DownloadsBuild StatusPatreon

    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

    Install

    npm i mongodb-repository

    DownloadsWeekly Downloads

    4

    Version

    0.0.0

    License

    MIT

    Last publish

    Collaborators

    • avatar