Package Exports
- hapi-mongodb
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-mongodb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Hapi-MongoDB
This is a plugin to share a common MongoDB connection pool across the whole Hapi server.
The versioning of this lib shares the major/minor versions of the mongodb library.
It takes 2 options :
- url: MongoDB connection string (eg.
mongodb://user:pass@localhost:27017
), - settings: Optional. Provide extra settings to the connection, see documentation.
Several objects are exposed by this plugin :
db
: connection object to the databaselib
: mongodb library in case you need to use it
Usage example :
function handler(request) {
var db = this.server.plugins['hapi-mongodb'].db;
db.collection('store').findOne({ id: request.query.id }, function(err, result) {
if (err) return request.reply(Hapi.error.internal('Internal MongoDB error', err));
request.reply(result);
});
}
Huge thanks to @dypsilon for his help into the making of this plugin.