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

actionhero-mongoskin

v0.0.1

Published

MongoDB initializers for actionHero backed by MongoSkin

Downloads

3

Readme

actionHero-mongoskin

MongoDB initializers for actionHero backed by MongoSkin

**WORK IN PROGRESS

What & Why

actionHero.js is a great toolkit for making reusable & scalable APIs. actionHero-mongoskin provides a simple initializer that exposes MongoDB support, which is not provided as a default in actionHero.js, via MongoSkin. It's also as a prove of concepts of how easy actionHero.js to extend as shown below.

How to

The easiest way is to install this package via npm and save it as dependency to your actionHero project.

npm install actionHero-mongoskin --save

Create an initializer, require actionHero-mongoskin then expose your initializer with mongoinit

// initializers/mongodb.js
mongo = require('actionHero-mongoskin').mongoinit;

exports.mongodb = mongo

That's it! Now you can access various mongoskin reference from api.mongo.* as listed in Exposed API.

Extend or override the initializer

You can also extend the default api.mongo.* to your liking. For that you need to manually expose your initializer rather than using actionHero-mongoskin built-in initializer as shown above.

// initializers/mongodb.js
mongo = require('actionHero-mongoskin').mongo;

exports.mongodb = function(api, next) {
  // Add a collection object shortcut:
  mongo.mycollection = mongo.db.collection('mycollection');
  api.mongo = mongo; // Now you can access `mycollection` by using `api.mongo.mycollection`
  return next();
};

Database Seeding

By default the initializer will also run database seed in server start, useful for providing sample data in development time. All you need to do is override the api.mongo.dbSeed function to setup the database.

// initializers/mongodb.js
mongo = require('actionHero-mongoskin').mongo;

exports.mongodb = function(api, next) {
  mongo.dbSeed = function(next) {
    api.mongo.collection('mycollection').insert({foo:'bar'}, function(error, result) {
      // ... further setup
      next() // <- IMPORTANT, dont forget to call this when you've finished seeding the database.
    })
  }
  api.mongo = mongo;
  return next();
};

If you don't want to run the dbSeed, set the seed config option of mongo section to false. See Configuration explanation below.

Configuration

To provide connection configuration you need to add mongo property to your config.js file. Shown below is the default value if no configData.mongo available in configuration

configData.mongo = {
  // Run database seed if `true`. Set to `false` in production.
  seed: true,
  host: "localhost",
  port: 27017,
  db: "test",
  user: "",
  pass: ""
}

Exposed API

api.mongo.db

api.mongo.collection

api.mongo.toId

api.mongo.ObjectId / api.mongo.ObjectID

api.mongo.Timestamp

api.mongo.router

api.mongo.Cursor

api.mongo.GridStore