{"id":22059240,"url":"https://github.com/opentable/hapi-mongodb-init","last_synced_at":"2025-05-12T19:44:23.244Z","repository":{"id":20519301,"uuid":"23798168","full_name":"opentable/hapi-mongodb-init","owner":"opentable","description":"plugin for initialising shared mongodb connections in a hapi app","archived":false,"fork":false,"pushed_at":"2020-05-22T11:39:21.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-18T09:02:10.757Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-08T16:15:18.000Z","updated_at":"2020-05-22T11:39:23.000Z","dependencies_parsed_at":"2022-09-05T07:01:31.548Z","dependency_job_id":null,"html_url":"https://github.com/opentable/hapi-mongodb-init","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fhapi-mongodb-init","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fhapi-mongodb-init/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fhapi-mongodb-init/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fhapi-mongodb-init/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentable","download_url":"https://codeload.github.com/opentable/hapi-mongodb-init/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253809750,"owners_count":21967788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T17:27:42.111Z","updated_at":"2025-05-12T19:44:23.212Z","avatar_url":"https://github.com/opentable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Hapi mongodb-init\n[![Build Status](https://travis-ci.org/opentable/hapi-mongodb-init.png?branch=master)](https://travis-ci.org/opentable/hapi-mongodb-init) [![NPM version](https://badge.fury.io/js/hapi-mongodb-init.png)](http://badge.fury.io/js/hapi-mongodb-init) ![Dependencies](https://david-dm.org/opentable/hapi-mongodb-init.png)\n\nInitialises mongodb connections (per database), and manages indexes.\n\nThis 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.\n\nUnfortunately 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.\nBreaking changes are introduced in the 3.x driver too then hapi-mongodb-init@4.x.x will work with mongodb@3.x.x.\n\nTo initialise:\n\n```js\nvar hapi = require(\"hapi\");\n\nhapi.createServer();\n\nserver.plugin.register({\n  plugin: require(\"hapi-mongodb-init\"),\n  options: {\n    dbs: [{\n         connectionString: 'mongodb://127.0.0.1/test',\n         name: 'myconnection',\n         dbName: 'mydatabase',\n         indexes: [\n          {\n              collection: 'mycoll',\n              name: \"myfield_1\",\n              fields: {\n                  myfield: 1\n              },\n              unique: false\n          }\n         ]\n      }],\n      mongo: require(\"mongodb\"),\n      connectionOptions: {\n          server: {\n              poolSize: 15,\n              socketTimeout: 10000\n          },\n          replSet: {\n              connectWithNoPrimary: false\n          }\n      }\n  }\n});\n\n```\n\n`connectionOptions` parameter can be passed either as a child of options or per db. `connectionOptions` set for specific db take precedance over general ones.\nDefault `connectionOptions`:\n```js\n{\n    server: {\n        poolSize: 5\n    },\n    replSet: {\n        connectWithNoPrimary: true\n    }\n}\n```\n\n\nOther options:\n\n- `failOnIndexes` (true | false): optionally ignore any errors while managing indexes\n\nTo use inside a module:\n\n```js\nvar dbs = require('hapi-mongodb-init');\n\nvar db = dbs.db('myconnection');\n\ndb.collection('mycoll').findOne({ myfield: 'foo'}, function(err, value){\n  console.log(value);\n});\n```\n\n__You're managing indexes inside your app, isn't that dangerous?__\n\nFor small data sets, (where building indexes is trivial), we find it works.\n\nYou can turn off the index management by setting:\n\n```js\nserver.plugin.register({\n  plugin: require(\"hapi-mongodb-init\"),\n  options: {\n    dbs: [{\n         connectionString: 'mongodb://127.0.0.1/test',\n         name: 'myconnection',\n         dbName: 'mydatabase',\n         manageIndexes: false\n      }],\n      mongo: require(\"mongodb\")\n  }\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fhapi-mongodb-init","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentable%2Fhapi-mongodb-init","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fhapi-mongodb-init/lists"}