mongoose-helpers-setup-db
returns a function that will return a mongoose connection promise when called; it should be used in conjunction with the http-server-request-handlers-db module.
the initial intent of this module is to provide a way to re-initialize a mongoose connection, on an http request, if the connection threw an error, on application startup or was lost after startup.
see the examples directory for an actual implementation using these two modules together.
table of contents
notes
logging
- error events will be logged to the console
- additional logging - if
options.connection.debug
is set totrue
the following events will also be logged to the console- connected
- connecting
- disconnected
- open
- reconnected
errors
- if an error occurs, the error will be attached to the db object as
db.error
.
installation
npm install mongoose-helpers-setup-db
api
/** * @param * @param * @param * * @returns */
event types
- connected
- connecting
- disconnected
- error
- open
- reconnected
usage
basic
var express = var connection = var mongoose = var setupDb = var app = var User = displayName: String email: String id: String photo: String var options = connection: debug: configdebug uri: database: configdatabase password: configpassword username: configusername schemas: 'User': User // elsewhere in your app on a routeappdb