npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yamongoose-bird

v0.1.0

Published

blue bird support for mongoose

Downloads

1

Readme

yamongoose-bird

blue bird support for mongoose.

based on mongoose-q, mongoose-bird.

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);
 Promise.promisifyAll(mongoose.Document.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!