Skip to content

bohdan-romanchenko-axon/k7-mongoose

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k7-mongoose

k7 adapter for mongoose ODM

Build Status

Lead Maintainer: Marcos Bérgamo

Example Usage

const Hapi = require('hapi');
const Server = new Hapi.Server();

Server.connection({host: 'localhost'});

let options = {
    adapter: require('k7-mongoose'),
    connectionString: 'mongodb://localhost:27017/K7Mongoose',
    promise: global.Promise
};

Server.register({
    register: require('k7'),
    options: options
}, (err) => {
    if (err) {
        throw err;
    }
    
    Server.start((err) => {
        if (err) {
            throw err;
        }
        
        Server.log('info', 'Server running at: ' + Server.info.uri);
    });
});

This example does the following:

  1. Setting the k7-mongoose adapter
  2. Setting the connectionString for mongoose connect
  3. Register the k7 to Hapi.js

Options

All the options available in Mongoose can be setted in connectionOptions.

Set up the models

You can define your models schema like you're already do, but you need to replace the const mongoose = require('mongoose'); on top of your models by update with const mongoose = require('k7-mongoose').mongoose();

Why this is required? Because mongoose is a singleton, therefore you need to use the k7-mongoose instantiated version.

About

K7 adapter for Mongoose ODM :squirrel:

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%