hapi-mongodb-profiles

Simple hapi plugin to manage mongodb connection profiles.

Usage no npm install needed!

<script type="module">
  import hapiMongodbProfiles from 'https://cdn.skypack.dev/hapi-mongodb-profiles';
</script>

README

hapi-mongodb-profiles

Simple hapi plugin to manage mongodb connection profiles

Build Status Dependency Status

Register plugin

server.pack.register({
    plugin: require('hapi-mongodb-profiles'),
    options: {
        // decorateRequest: false // default: true
        options: {
            // default options for all profiles, will be extended by local profile options
        }
        profiles: [
            { name: 'test', url: 'hapi://test/db', options: {
                // local profile options
            }}
        ]
    }
}

Get database

server.plugins['hapi-mongodb-profiles'].db('profileName')
request.db('profileName')
request.db() // first database/profile will be returned

Get collection

server.plugins['hapi-mongodb-profiles'].collection('profileName', 'collectionName')
request.collection('test') // first database/profile will be used
request.collection('profile', 'test')