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.jsmongo = mongoinit; exportsmongodb = 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.jsmongo = mongo; exports { // Add a collection object shortcut: mongomycollection = mongodb; apimongo = mongo; // Now you can access `mycollection` by using `api.mongo.mycollection` return ;};
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.jsmongo = mongo; exports { mongo { apimongo } apimongo = mongo; return ;};
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
configDatamongo = // Run database seed if `true`. Set to `false` in production. seed: true host: "localhost" port: 27017 db: "test" user: "" pass: ""