Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghostbar/hapi-mongodb2
Hapi's MongoDB native driver 2.0 plugin
https://github.com/ghostbar/hapi-mongodb2
Last synced: 7 days ago
JSON representation
Hapi's MongoDB native driver 2.0 plugin
- Host: GitHub
- URL: https://github.com/ghostbar/hapi-mongodb2
- Owner: ghostbar
- License: isc
- Created: 2015-01-03T05:14:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-23T00:13:51.000Z (about 9 years ago)
- Last Synced: 2024-10-18T06:51:17.699Z (29 days ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
hapi-mongodb2
=============Hapi (^8.0) plugin for the MongoDB native driver 2.0.
Install
-------npm install --save mongodb@2 hapi-mongodb2
Register plugin
---------------var Hapi = require('hapi');
var server = new Hapi.Server();server.register({
register: require('hapi-mongodb2')
opts: { url: 'mongodb://user:[email protected]:port/database' }
}, function (err) {
if (err) console.error(err);
});Use plugin
----------The object returned by `MongoClient.connect` is exposed on `server.plugins['hapi-mongodb2'].client` and binded to the context on routes and extensions as `this.mongo`.
If by any chance you need to use the `mongodb` library itself you can get it from `server.plugins['hapi-mongodb2'].library`.
server.route({
method: 'GET',
path: '/users',
handler: function (request, reply) {
var mongo = request.server.plugins['hapi-mongodb2'].client;
mongo.collection('users').find({}).toArray(function (err, users) {
reply(users);
});
}
}, {
method: 'GET',
path: '/databases',
handler: function (request, reply) {
var mongo = this.mongo;
mongo.admin().listDatabases(function (err, dbs) {
reply(dbs);
});
}
});License
-------Licensed under the terms of the ISC. A copy of the license can be found in the file `LICENSE`.
© 2015, Jose-Luis Rivas ``