0.3.0 • Published 8 years ago

ab-mongodb v0.3.0

Weekly downloads
8
License
MIT
Repository
github
Last release
8 years ago

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

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago