Skip to content

asilluron/hapi-mongoose

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

hapi-mongoose

Circle CI

Stories in Ready

An hapi plugin to handle Mongoose handshake and initial setup.

Install

npm install --save hapi-mongoose

Requirements

  • Mongoose
npm install --save mongoose

Usage

const options = {
    promises: 'native',
    uri: 'mongodb://localhost:27017'
};

const server = new Hapi.Server();

await server.register({
    plugin: require('hapi-mongoose'),
    options: options
});

const db = server.plugins['hapi-mongoose'].connection;

const mongoose = server.plugins['hapi-mongoose'].lib;

Example

const db = server.plugins['hapi-mongoose'].connection; // Get the current connection for this server instance
const mongoose = server.plugins['hapi-mongoose'].lib;
const Schema = mongoose.Schema;

const tankSchema = new Schema({
  // Tank properties
});

const Tank = db.model('Tank', tankSchema);

const small = new Tank({ size: 'small' });

small.save(function (err) {
  if (err) return handleError(err);
  // Saved!
});

It is important to use server.plugins['hapi-mongoose'].lib instead of require('mongoose') due to this issue.

Options

About

Hapi Plugin to handle Mongoose handshake and initial setup

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •