New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongoose-bird

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-bird

blue bird support for mongoose

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

mongoose-bird

blue bird support for mongoose.

based on mongoose-2.

What is it?

mongoose-bird uses the bluebird's Promise.promisifyAll function which will add a Async function for each function on mongoose :

  • mongoose.Model
  • mongoose.Model.prototype
  • mongoose.Query.prototype

So all mongoose-bird does it to call:

 Promise.promisifyAll(mongoose.Model);
 Promise.promisifyAll(mongoose.Model.prototype);
 Promise.promisifyAll(mongoose.Query.prototype);

usage

var mongoose = require('mongoose-bird')(require('mongoose'));
// verbose way: mongooseQ is unused
var mongoose = require('mongoose'),
    mongooseBird = require('mongoose-bird')(mongoose)
// shortest way: mongoose will be loaded by mongoose-bird
var mongoose = require('mongoose-bird')();
  • use Async model statistics functions:
SomeModel.findByIdAsync(....blahblah...)
  .then(function (result) { ... })
  .catch(function (err) { ... });
  • use Async model functions:
var someModel = new SomeModel(...);
someModel.populateAsync()
  .then(function (result) { ... })
  .catch(function (err) { ... });
  • use Async query methods:
SomeModel.find(...).where(...).skip(...).limit(...).sort(...).populate(...)
  .execAsync() // no 'Async' suffix for model statics except for execAsync()
  .then(function (result) { ... })
  .catch(function (err) { ... });
  • to use Async with spread:
var mongoose = require('mongoose-bird')(require('mongoose'));
SomeModel.updateAsync(...)
  .spread(function (affectedRows, raw) { ... })
  .catch(function (err) { ... });
...
var model = new SomeModel();
...
model.saveAsync()
  .spread(function (savedDoc, affectedRows) { ... })
  .catch(function (err) { ... });
...
  • to define custom statics/instance methods using Async
SomeSchema.statics.findByName = function (name) {
  return this.findAsync({name: name}); // NOTE: returns Promise object.
};
...
var SomeModel = mongoose.model('Some', SomeSchema);
SomeModel.findByName('foo').then(function(result) {
  console.log(result);
});

NOTE: this is not a feature of mongoose-bird

That's all folks!

FAQs

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