{"id":42836,"library":"hapi-multi-mongo","title":"hapi-multi-mongo","description":"A Hapi.js plugin for managing multiple MongoDB connections, designed for Hapi >= 17. Current version 5.1.1. It decorates the server or request object with MongoDB client instances, supporting complex configurations with multiple servers, custom names, and connection options. Differs from hapi-mongodb by focusing on multiple connections and offering flexible configuration via strings, objects, or arrays.","status":"active","version":"5.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/metoikos/hapi-multi-mongo","tags":["javascript","hapi","mongodb"],"install":[{"cmd":"npm install hapi-multi-mongo","lang":"bash","label":"npm"},{"cmd":"yarn add hapi-multi-mongo","lang":"bash","label":"yarn"},{"cmd":"pnpm add hapi-multi-mongo","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for plugin registration and decoration","package":"@hapi/hapi","optional":false}],"imports":[{"note":"Must pass options as second argument. Plugin is CommonJS only.","wrong":"server.register(require('hapi-multi-mongo'))","symbol":"register","correct":"await server.register({ plugin: require('hapi-multi-mongo'), options })"},{"note":"Access via decoration if decorate: true (default false, so request.mongo).","wrong":"server.plugins['hapi-multi-mongo'].mongo.db_name.collection","symbol":"server.mongo","correct":"server.mongo.db_name.collection('test')"},{"note":"Decorated on request object if decorate: false (default).","wrong":"request.server.mongo","symbol":"request.mongo","correct":"request.mongo.db_name.collection('test')"}],"quickstart":{"code":"const Hapi = require('@hapi/hapi');\n\nconst init = async () => {\n  const server = Hapi.server({ port: 3000 });\n\n  await server.register({\n    plugin: require('hapi-multi-mongo'),\n    options: {\n      connection: 'mongodb://localhost:27017/mydb',\n      decorate: true\n    }\n  });\n\n  server.route({\n    method: 'GET',\n    path: '/',\n    handler: async (request, h) => {\n      const db = server.mongo.mydb;\n      const result = await db.collection('items').findOne({});\n      return result;\n    }\n  });\n\n  await server.start();\n  console.log('Server running on %s', server.info.uri);\n};\n\nprocess.on('unhandledRejection', (err) => {\n  console.log(err);\n  process.exit(1);\n});\n\ninit();","lang":"javascript","description":"Registers hapi-multi-mongo with a single MongoDB connection and decorates server.mongo. Defines a route that queries a collection."},"warnings":[{"fix":"Access database via server.mongo.dbName or request.mongo.dbName, then call .collection() on that db object.","message":"Version 4.0.0 replaced db object with MongoClient; use db.collection() instead of db.collection() on client.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Install hapi-multi-mongo@3.1.1 for older Hapi versions.","message":"Hapi 17+ required; for Hapi <=16 use version 3.1.1.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Set decorate: true in options to access via server.mongo.","message":"If decorate is false (default), mongo is only available on request.mongo, not server.mongo.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always include a database in the URI or provide an explicit name per connection.","message":"Connection names: if URI includes database, the db name is used as key; if no database, you must provide a name in config object.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'17':16 '5.1.1':19 'array':60 'client':29 'complex':32 'configur':33,55 'connect':12,40,51 'current':17 'custom':37 'decor':21 'design':13 'differ':42 'flexibl':54 'focus':48 'hapi':2,15,45,62 'hapi-mongodb':44 'hapi-multi-mongo':1 'hapi.js':6 'instanc':30 'javascript':61 'manag':9 'mongo':4 'mongodb':11,28,46,63 'multi':3 'multipl':10,35,50 'name':38 'object':26,58 'offer':53 'option':41 'plugin':7 'request':25 'server':23,36 'string':57 'support':31 'version':18 'via':56","created_at":"2026-06-05T16:56:53.718105+00:00","updated_at":"2026-06-05T16:56:53.718105+00:00","problems":[{"fix":"Update to hapi-multi-mongo@5.x and ensure mongodb driver is installed (npm install mongodb).","cause":"Older version or wrong usage; plugin expects MongoDB driver 3.x+.","error":"Error: hapi-multi-mongo requires a MongoClient instance"},{"fix":"Enable decorate:true or use request.mongo. Verify connection name matches database name.","cause":"Accessing server.mongo without decorate:true, or incorrect connection name.","error":"TypeError: Cannot read property 'collection' of undefined"},{"fix":"Provide a name property for each connection object, e.g., { uri: '...', name: 'myConn' }.","cause":"Missing name when URI has no database or array of URIs without names.","error":"Error: Connection name not found in configuration"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/metoikos/hapi-multi-mongo#readme","github":"ssh://git@github.com/metoikos/hapi-multi-mongo","docs":null,"changelog":null,"pypi":null,"npm":"hapi-multi-mongo","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}