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

mongoomise

v0.0.8

Published

promisify mongoose by any promise library

Downloads

52

Readme

mongoomise

promisify mongoose by any promise library

Support List

Default Usage


var mongoose = require('mongoose')

// load your models first
var User = mongoose.mode('User', UserSchema)
//...


// choose your fav library
require('mongoomise').promisifyAll(mongoose, require('bluebird'))
// require('mongoomise').promisifyAll(mongoose, require('q'))
// require('mongoomise').promisifyAll(mongoose, require('rsvp'))
// require('mongoomise').promisifyAll(mongoose, require('when'))
// require('mongoomise').promisifyAll(mongoose, require('es6-promise'))

// start flying
User.findOneAsync().then(function(user){
	user.pv += 1
	return user.saveAsync()
}).then(function(results){
	console.log(results)
})

Multipe Connections


var mongoose = require('mongoose')
var mongoomise = require('mongoomise')
var connection = mongoose.createConnection('..')

//load models
var User = connection.model('User', UserSchema)
var UserX = mongoose.model('User', UserSchema)
//...

//just promisify the connection, the mongoose will be auto promisified
mongoomise.promisifyAll(connection, require('bluebird'))

// start flying
User.findOneAsync().then(function(user){
	user.pv += 1
	return user.saveAsync()
}).then(function(results){
	console.log(results)
	UserX.findOneAsync()
	// ...
})

Updated

  • support promisify connection from mongoose.createConnection
  • add a test for mongoose.createConnection
  • support promisify custom Schema static methods

TODO

  • support custom instance methods

Notes

  • Do I have to change my existing mongoose related code? No, just follow your old style.
  • Does hooks like Schema.pre work as usual? Yes. some useful discussion here
  • Does it support custom model static method? Yes!
  • mongoomise.promisifyAll should be invoked after all models are loaded

mongoose basics

  • your models extends from mongoose.Model
  • schemas are stored on global mongoose but models may not
  • mongoose.models.ModelName equals to mongoose.model('ModelName')
  • ModelName.schema equals to mongoose.modelSchemas.ModelName
  • static methods should be extended on mongoose.Model with a dynamic context
  • instance methods should be extended on mongoose.Model.prototype
  • custom model static methods are stored in MyModel.schema.statics
  • connection instance store its own models
  • it will lookup to mongoose when no models found on connection

Test

mocha ./test/mocha

Benchmark

node benchmark

the benchmark contains:

  • bluebird - using bluebird.promisifyAll(mongoose)
  • mongoomise/bluebird - using mongoomise with bluebird
  • mongoomise/Q - using mongoomise with Q
  • mongoomise/RSVP - using mongoomise with RSVP
  • mongoomise/when - using mongoomise with when.js
  • mongoomise/es6Promise - using mongoomise with es6-promise

in my MacAir, mongoomise/bluebird win the championship.