Socket
Socket
Sign inDemoInstall

hapi-mongodb2

Package Overview
Dependencies
47
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hapi-mongodb2

Hapi's MongoDB 2.0 native driver plugin


Version published
Maintainers
1
Created

Readme

Source

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:password@domain.tld: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 <me@ghostbar.co>

Keywords

FAQs

Last updated on 23 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc