Skip to content

jaysaurus/co-koa-mongoose-plugin

Repository files navigation

Build Status Coverage Status Greenkeeper badge Test For Vulnerabilities

Co.Koa header

co-koa-mongoose-plugin

As of [email protected] the mongoose API has been fully decoupled into a plugin. For details on how to use this plugin once it has been installed please visit the Models page of the Co.Koa documentation

co-koa-mongoose@^1.8.0 has only been tested with co-koa-core@^1.16.0 and may contain breaking changes with older versions.

installation

add co-koa-mongoose-plugin to a Co.Koa project instance via:

npm i co-koa-mongoose-plugin --save

within your app.js add the co-koa-mongoose-plugin as a requirement and pass the mongoosePlugin call as below:

const fs = require('fs');
const mongoosePlugin = require('co-koa-mongoose-plugin');

if (fs.existsSync('./node_modules')) {
  const CoKoa = require('co-koa-core');
  try {
    const coKoa = CoKoa(__dirname).launch(mongoosePlugin()); // <= HERE!
    ...

The mongoosePlugin can optionally be called with a configuration object. The default configuration object is as below:

SessionPlugin({
  connectionString = 'mongodb://localhost:27017/coKoa',
  promise = global.Promise,
  plugins = undefined
})

The connectionString property expects either a list of strings or an object containing environment properties matching those supplied to your Co.Koa environment at launch (see installation & execution documentation for more information):

connectionString: {
  development: 'mongodb://etc',
  test: 'mongodb://etc',
  etc: 'mongodb://etc',
}
...

the promise property expects a promise library for mongoose to use on asynchronous requests. You are strongly encouraged to supply an alternative promise library to mongoose. At the time of writing, the global promise library is significantly slower than other promise libraries (see, for example bluebird)

the plugins property can be supplied an array of additional Co.Koa plugins. These should point to methods based on the boilerplate below:

(mongoose) => {
  ...
  return {
    init (app, $) => {
      ...
    }
  }
}

About

A plugin enabling Co.Koa to access mongoose databases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published