🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mongodb-promise

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-promise

A mongodb-native promise library

0.0.2
Source
npm
Version published
Weekly downloads
47
95.83%
Maintainers
1
Weekly downloads
 
Created
Source

mongodb-promise

Build Status

Mongodb-promise is a light promise wrapper around node-mongodb-native.

Quick Examples

// Obtaining a connection
var mp = require('mongodb-promise');

mp.MongoClient.connect("mongodb://127.0.0.1:27017/test").then(function(db){
    db.close().then(console.log('success'));
}, function(err) {
    console.log(err);
});

// Read Db stats
mp.MongoClient.connect("mongodb://127.0.0.1:27017/test")
.then(function(db){
    return db.stats().then(function(stats) {
        console.log(stats);
        db.close().then(console.log('success'));
    })
})
.fail(function(err) {console.log(err)});

// Insert documents
mp.MongoClient.connect("mongodb://127.0.0.1:27017/test")
    .then(function(db){
        return db.collection('test')
            .then(function(col) {
                return col.insert([{a : 1}, {a : 2}])
                    .then(function(result) {
                        console.log(result);
                        db.close().then(console.log('success'));
                    })
            })
})
.fail(function(err) {console.log(err);});

// Read documents
mp.MongoClient.connect("mongodb://127.0.0.1:27017/test")
    .then(function(db){
        return db.collection('test')
            .then(function(col) {
                return col.find({a : 1})
                    .then(function(cursor){
                        return cursor.toArray();
                    })
                    .then(function(items) {
                        console.log(items);
                        db.close().then(console.log('success'));
                    })
        })
})
.fail(function(err) {console.log(err)});

Download

npm install mongodb-promise

Test

make test

Keywords

mongo

FAQs

Package last updated on 23 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts