0.2.0 • Published 9 years ago

mongodb-promises v0.2.0

Weekly downloads
17
License
ISC
Repository
github
Last release
9 years ago

mongodb-promises

A simple promise wrapper around mongodb(peer dependency) nodejs drivers.

How to use it?

In a big app.

  • Create a file may be db.js and put below code into that.
var config      = require('config'),
    db          = require('mongodb-promises').db(config.db.host, config.db.name);
module.exports = db;
  • Now you can use db.js any no. of time time making sure all sharing same db object instance.
var db          = require('./db')
    todoColl    = db.collection('todos');

todoColl.insert([{text: 'first task to do'}, {text: 'second task to do'}])
        .then(function (resultArr) {
            console.log('saved successfully');
        })
        .catch(function (err) {
            console.error('Error on insert ', err);
        });

Simple one file script

var db          = require('mongodb-promises').db('host:port', 'db_name'), // host can be array in case of replSet
    todoColl    = db.collection('todos');

todoColl.insert([{text: 'first task to do '}, {text: 'second task to do'}])
        .then(function (resultArr) {
            console.log('saved successfully');
        })
        .catch(function (err) {
            console.error('Error on insert ', err);
        });

List of DB methods

  • collection(collectionName, options) Returns a collection object to perform operations on a collection using promises.
  • drop() To drop database, call it carefully.
  • createCollection(name, options) Creates a collections on mongodb, usefull if you want collections be created before use(Mongodb can create collection if not exist on first document creation).

List of Collection methods

Changes Log

0.2.0

  • Mongodb package as peer dependency.
0.2.0

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago