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

mongoose-wrangler

v0.3.3

Published

Wrangle up some Mongoose and plugins

Readme

Mongoose Wrangler

Wrangle up some Mongoose and plugins

Mongoose Wrangler takes the guesswork out of managing mongoose-powered connections to MongoDB. Mongoose provides auto-reconnect and other niceties, but there is still some setup involved, especially with multiple connections. Wrangler attempts to automate as much as possible, including loading of mongoose model definition files for each connection.

Mongoose Wrangler can also optionally register commonly-used mongoose plugins such as mongoose-datatable and gridfs-stream. Other plugins are easily added, so send in those PRs.

Installation

$ npm install mongoose-wrangler

Usage

MongooseWrangler = require 'mongoose-wrangler'

# initialize with options
mw = new MongooseWrangler
  debug: true              # default: false
  address: "192.168.0.2"   # default: "127.0.0.1"
  db: "mydb"               # default: "test"
  datatable: true          # default: false
  gridfs: true             # default: false
  modelPath: "./db-models" # default: "./models"
  additional: [            # optional array of additional connections
    address: "127.0.0.1"
    db: "otherDb"
    modelPath: "./other"   # models to load specifically for additional connection
  ]

# manually disconnect
mw.disconnect()

Depending on the project setup, using mongoose = require('mongoose') may point to a different instance of mongoose. To access the mongoose instance used by mongoose-wrangler:

mongoose = require('mongoose-wrangler').mongoose

Additional Connections

Mongoose Wrangler handles multiple-connections with a few extra steps:

  1. Model files should export a function model(connection) which Mongoose Wrangler can call with the additional connection after it has been set up. i.e.:
exports.model = (connection) ->
  connection.model "user", schema
  1. Recall the model for an additional connection using the connection's index in the additional array:
MongooseWrangler.additional[0].model("my-model")

Express Streaming with GridFS

Take advantage of Node.js streaming with GridFS and Express.js. Requested files are streamed to client a chunk at a time instead of loading completely into memory.

mw = require('mongoose-wrangler')
gridfs = mw.gridfs

# or for one of the "additional" connections:
# gridfs = mw.Grid(mw.additional[0].db, mw.mongoose.mongo)

exports.getFile = (req, res) ->
  options =
    filename: req.params.filename

  # first check if file exists because createReadStream on non-existing file bombs hard
  gridfs.exist options, (err, found) ->
    handleError(res, err) if err
    if found
      # set up a read stream and pipe to express response for efficiency
      readstream = gridfs.createReadStream options
      readstream.pipe res
    else
      res.send 404

Debug

Using the debug: true option will print out a little more information such as each model as it is loaded.

Testing

$ npm test

License

MIT