Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-mongodb-init

Package Overview
Dependencies
Maintainers
4
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-mongodb-init

initialises mongo db connections for hapi

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by900%
Maintainers
4
Weekly downloads
 
Created
Source

#Hapi mongodb-init Build Status NPM version Dependencies

Initialises mongodb connections (per database), and manages indexes.

This module doesn't explicitly depend on mongodb, but requires it to be passed in on the options. This means you're free to use your "favourite" version.

Unfortunately thanks to the breaking changes introduced in the 2.x driver then hapi-mongodb-init@3.x.x will work with mongodb@2.x.x.

To initialise:

var hapi = require("hapi");

hapi.createServer();

server.plugin.register({
  plugin: require("hapi-mongodb-init"),
  options: {
    dbs: [{
         connectionString: 'mongodb://127.0.0.1/test',
         name: 'myconnection',
         indexes: [
          {
              collection: 'mycoll',
              name: "myfield_1",
              fields: {
                  myfield: 1
              }
          }
         ]
      }],
      mongo: require("mongodb")
  }
});

Other options:

  • failOnIndexes (true | false): optionally ignore any errors while managing indexes

To use inside a module:

var dbs = require('hapi-mongodb-init');

var db = dbs.db('myconnection');

db.collection('mycoll').findOne({ myfield: 'foo'}, function(err, value){
  console.log(value);
});

You're managing indexes inside your app, isn't that dangerous?

For small data sets, (where building indexes is trivial), we find it works.

You can turn off the index management by setting:

server.plugin.register({
  plugin: require("hapi-mongodb-init"),
  options: {
    dbs: [{
         connectionString: 'mongodb://127.0.0.1/test',
         name: 'myconnection',
         manageIndexes: false
      }],
      mongo: require("mongodb")
  }
});

Keywords

FAQs

Package last updated on 31 Jul 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc