
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
hapi-mongodb-init
Advanced tools
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. Tested with 1.4.7 and up.
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")
}
});
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")
}
});
FAQs
initialises mongo db connections for hapi
We found that hapi-mongodb-init demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.