ab-mongodb

0.3.0 • Public • Published

ab-mongodb

MongoDB driver wrapper using ES6 Promises.

Installation

npm install ab-mongodb

Usage

Import the module const mongodb = require('ab-mongodb') and get a reference to work with it.

Create a client instance with your settings let itemsDB = new mongodb(url, collectionName, hasObjectID)

Then you can operate over the collection with a basic set of methods:

INSERT

let itemsDB = new MongoDB(url, 'items', true)
itemsDB.inserting({})
    .then(() => {
        console.log('inserted !!!')
    })
    .catch((err) => {
        console.error('error: ' + err)
    })

FIND

let itemsDB = new MongoDB(url, 'items', true)
itemsDB.finding()
    .then(() => {
        console.log('found !!!')
    })
    .catch((err) => {
        console.error('error: ' + err)
    })

UPDATE

let itemsDB = new MongoDB(url, 'items', true)
itemsDB.finding()
    .then((docs) => {
        let doc = docs[0]
        doc.updated = new Date()
        itemsDB.updating({_id:doc._id}, doc)
            .then(() => {
                console.log('updated !!!')
            })
            .catch((err) => {
                console.error('error: ' + err)
            })
    })
    .catch((err) => {
        console.error('error: ' + err)
    })

REMOVE

let itemsDB = new MongoDB(url, 'items', true)
itemsDB.finding()
    .then((docs) => {
        let doc = docs[0]
        doc.updated = new Date()
        itemsDB.removing({_id:doc._id})
            .then(() => {
                console.log('deleted !!!')
            })
            .catch((err) => {
                console.error('error: ' + err)
            })
    })
    .catch((err) => {
        console.error('error: ' + err)
    })

Road map

More operations to wrap

Licence

The MIT License (MIT)

Copyright (c) 2016 [Àgora Binaria] (http://agorabinaria.com)

/ab-mongodb/

    Package Sidebar

    Install

    npm i ab-mongodb

    Weekly Downloads

    0

    Version

    0.3.0

    License

    MIT

    Last publish

    Collaborators

    • albertobasalo