Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

hapi-multi-mongoose

shintotuna2MIT1.0.0

Hapi plugin for muliple mongoose connections

hapi, mongoose

readme

Installation

npm i -S hapi-multi-mongoose

Usage

const Hapi = require('hapi');
const HapiMultiMongooose = require('hapi-multi-mongoose');
const server = new Hapi.Server();

server.register({
    register: HapiMultiMongooose,
    options: {
        dbs: [{
            uri: 'mongodb://localhost/marketing',
            name: 'marketing'
        }, {
            uri: 'mongodb://localhost/sales',
            name: 'sales'
        }]
    }
});

const { mongoose, connections } = server.plugins['hapi-multi-mongoose'];
const Schema = mongoose.Schema;

const productSchema = new Schema({ name: String });

const Product = connections.sales.model('Product', productSchema);

const phone = new Product({ name: 'iPhone' });

phone.save((err) => {
    if (err) {
        return err;
    }

    // Done
})