You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since a breaking change of MongoDB client library from v2.x to v3.x, method MongoClient.connect() returns a Connection object instead of a Database object, caused app unable to start openKB using MongoDB as its database.
The text was updated successfully, but these errors were encountered:
You can add a few lines to the app.js file to extract the mongodb database name from the connection string. The mongodb 3.x driver is different, it passes back a client instead of a db, so you need to create a db instance. ie: let db = client.db(dbName);
I've tested out the code below and it works. Not sure if this will work for all connection strings though, and it's a bit of a hack... ie: maybe we should be passing in the db name instead. It also doesn't handle errors, like if the regex group 1 doesn't exist. But feel free to use it if you want.
MongoClient.connect(config.settings.database.connection_string, {}, (err, client) => {
// On connection error we display then exit
if(err){
console.error('Error connecting to MongoDB: ' + err);
process.exit();
}
const mongoDBNameRegEx = "^(?:mongodb:\\/\\/)(?:.+)(?:\\/+)(.+)(?:\\?+)(?:.+)";
let dbName = config.settings.database.connection_string.match(mongoDBNameRegEx)[1];
let db = client.db(dbName);
In november, Heroku will close its MongoDb addon, so I migrated my openKb database from heroku.com to mongodb.com.
After this, the 'npm start' command always failed with "db.connection" error...
Since a breaking change of MongoDB client library from v2.x to v3.x, method MongoClient.connect() returns a Connection object instead of a Database object, caused app unable to start openKB using MongoDB as its database.
The text was updated successfully, but these errors were encountered: