A Hapi.js plugin that shares a MongoDB connection pool across the entire server. Current stable version 11.0.0, requires Node.js >= 18 and @hapi/hapi >= 20.0.0. Ships with mongodb driver 6.x. Provides server/request decorations for easy access to MongoClient, Db, ObjectID, and the mongodb library. Supports multiple connections via an array of options. Simplifies MongoDB integration in Hapi applications by managing connections and decorations automatically.
npm install hapi-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates registering the hapi-mongodb plugin, using decorate, and accessing the database via request.mongo.db.
Upgrade to Node.js >=18, @hapi/hapi >=20. Update mongodb usage to match driver 6.x (e.g., MongoClient.connect signature changes).
Always provide an explicit url with credentials and proper host.
If using multiple connections, set decorate to a unique string per connection.
Correct pattern: await server.register({ plugin: require('hapi-mongodb'), options: {...} });Ensure options.decorate is set to true or a string, and access the correct property: request.mongo.db.
Run: npm install @hapi/hapi
Use valid mongodb:// URL, e.g., mongodb://user:pass@localhost:27017/dbname
Use async/await: const server = Hapi.server(); await server.register(...);