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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mongootils

v0.0.3

Published

Promisified connection utils for Mongoose

Downloads

8

Readme

mongootils

Build Status

Promisified (Bluebird) connection utils for Mongoose

Requirements

mongootils requires Mongoose as a peer dependency, so make sure you have it installed in your project.

Installation

npm i --save mongootils

Usage

var Mongootils = require('mongootils');

var db = new Mongootils('mongodb://localhost/database');
db.connect()
.then(function(connection){
  console.log('Connected to ' + db.getConnectionURI());
  return db.disconnect();
})
.then(function(uri){
  console.log('Disconnected from ' + uri);
});

Using ExpressJS

var Mongootils = require('mongootils');
var app = require('express')();

var db = new Mongootils('mongodb://localhost/database');
db.connect()
.then(function(connection){
  console.log('Connected to ' + db.getConnectionURI());
  app.set('db', db);
});

// In another place...
app.get('/api/users', function(req, res){
  var db = req.app.get('db');
  var User = db.model('User');
  // ...
});

API

new Mongootils(NativeConnection connection)

var db = new Mongootils(mongoose.connections[3]);

new Mongootils(uri, options)

The same arguments as mongoose.connect or mongoose.createConnection).

var db = new Mongootils('mongodb://localhost/mongootils_test', { /* mongoose options object */ });

db.connect()

Returns a Bluebird promise that is resolved when the connection has been effectively opened, or rejected otherwise.

db.disconnect()

Returns a Bluebird promise that is resolved when the connection has been effectively closed, or rejected otherwise.

db.is()

Checks for the underlying connection state.

if (db.is('connecting') || db.is('connected')) {
  // Listen to Thin Lizzy
} else {
  // ... or listen to Thin Lizzy
}

db.getConnection()

Retrieves the underlying NativeConnection object.

db.getConnectionURI()

Returns the mongoose-valid connection URI for the underlying connection.

  var db = new Mongootils('mongodb://localhost:27000,127.0.0.1:27001/my_db');
  console.log(db.getConnectionURI()); // prints 'mongodb://localhost:27000/my_db,mongodb://127.0.0.1:27001/my_db'

TODO

  1. Test multiple connections to the same database with two different Mongootils object
  2. Test multiple database URI

Contributions

  1. Code feature
  2. Write tests
  3. Pull Request