Skip to content

Repository files navigation

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

constoptions={promises: 'native',uri: 'mongodb://localhost:27017'};constserver=newHapi.Server();awaitserver.register({plugin: require('hapi-mongoose'),options: options});constdb=server.plugins['hapi-mongoose'].connection;constmongoose=server.plugins['hapi-mongoose'].lib;

Example

constdb=server.plugins['hapi-mongoose'].connection;// Get the current connection for this server instanceconstmongoose=server.plugins['hapi-mongoose'].lib;constSchema=mongoose.Schema;consttankSchema=newSchema({// Tank properties});constTank=db.model('Tank',tankSchema);constsmall=newTank({size: 'small'});small.save(function(err){if(err)returnhandleError(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

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages