GithubHelp home page GithubHelp logo

mongodb-bluebird's Introduction

mongodb-bluebird

Build Status

Add promise to the node-mongodb-native.

Installation

npm install mongodb-bluebird

Quick examples

var mongo = require('mongodb-bluebird');
//open connection to the database
mongo.connect("mongodb://localhost:27017/mongodb-bluebird").then(function(db) {
    //close connection to the database
    return db.close().then(function() {
        console.log('success');
    });
}).catch(function(err) {
  console.error("something went wrong");
});

//find users
mongo.connect("mongodb://localhost:27017/mongodb-bluebird").then(function(db) {
    //get the user collection
    var users = db.collection('users');
    return users.find().then(function(users) {
        console.log(users);
    }).catch(function(err) {
        console.error("something went wrong");
    });
});

//find one user
users.findOne().then(function(user) {
    console.log(user);
});

//find by id
users.findById('507f191e810c19729de860ea').then(function(user) {
    console.log(user);
});

Get a collection

var users = db.collection('users');

The _id field will be automatically converted into ObjectId. If you want to convert automatically some other fields into ObjectId just pass an array as second parameter :

var users = db.collection('users', {
	ObjectIds: [`your', 'fields']
});

If you want to disable ObjectId conversion for `_id:

var users = db.collection('users', {
	ObjectId: false
});

API

###Top Level

  • mongodb - raw mongodb driver

###Collection MongoDB Collection MongoDB Queries

  • find([query][, fields][, options])
  • findOne([query][, fields][, options])
  • findById(oid[, fields][, options])
  • insert(docs[, options])
  • update(query, document[, options])
  • updateById(oid, document[, options])
  • remove([query][, options])
  • removeById(oid[, options])
  • count([query][, options])
  • save([doc][, options])
  • findAndModify(query, sort, doc[, options])
  • findAndRemove(query, sort[, options])
  • group(keys, condition, initial, reduce, finalize, command[, options])
  • aggregate(array[, options])
  • drop()
  • rename(newName[, options])
  • createIndex(fieldOrSpec[, options])
  • ensureIndex(fieldOrSpec[, options])
  • dropIndex(name)

###Db MongoDB Db

  • close()
  • admin()
  • collectionNames([collectionName][, options])
  • collections()
  • eval(code[, parameters][, options])
  • logout()
  • authenticate(username, password[, options])
  • addUser(username, password[, options])
  • removeUser(username[, options])
  • createCollection(collectionName[, options])
  • dropCollection(collectionName)
  • renameCollection(fromCollection, toCollection[, options])
  • dropDatabase()
  • stats([, options])

##TODO

  • Write some tests

mongodb-bluebird's People

Contributors

khuongduybui avatar pradel avatar romanarranz avatar toddbluhm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dirrk romanarranz

mongodb-bluebird's Issues

aggregate issue

Hi, pls check this, i hav problem with "aggregate"
this is error: "Unhandled rejection TypeError: Cannot read property 'out' of undefined"
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.