Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77
decreased by-70.83%
Maintainers
1
Weekly downloads
 
Created
Source

mongodb-promise

Build Status

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

Quick Examples

var mp = require('mongodb-promise');

// Obtaining a connection
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 all 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}).toArray()
                        .then(function(items) {
                            console.log(items);
                            db.close().then(console.log('success'));
                        })
            })
})
.fail(function(err) {console.log(err)});

// Read each document
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}).each(function(doc) {
                    console.log(doc);
                })
                .then(function() {
                    db.close().then(console.log('success'));
                })
        })
})
.fail(function(err) {console.log(err);});

Download

npm install mongodb-promise

Test

make test

Keywords

FAQs

Package last updated on 28 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc