diff --git a/packages/generator-feathers/generators/connection/index.js b/packages/generator-feathers/generators/connection/index.js index ae39a458f3..84c78a00d3 100644 --- a/packages/generator-feathers/generators/connection/index.js +++ b/packages/generator-feathers/generators/connection/index.js @@ -68,6 +68,7 @@ module.exports = class ConnectionGenerator extends Generator { case 'mongodb': this.dependencies.push(adapter); + this.dependencies.push('mongodb-core'); return connectionString; case 'mysql': diff --git a/packages/generator-feathers/generators/connection/templates/mongodb.js b/packages/generator-feathers/generators/connection/templates/mongodb.js index 006bc2293f..0f96be6176 100644 --- a/packages/generator-feathers/generators/connection/templates/mongodb.js +++ b/packages/generator-feathers/generators/connection/templates/mongodb.js @@ -1,15 +1,15 @@ -const url = require('url'); +const parse = require('mongodb-core').parseConnectionString; const MongoClient = require('mongodb').MongoClient; module.exports = function (app) { const config = app.get('mongodb'); - const dbName = url.parse(config).path.substring(1); - const promise = MongoClient.connect(config).then(client => { + const promise = MongoClient.connect(config, { useNewUrlParser: true }).then(client => { // For mongodb <= 2.2 if(client.collection) { return client; } - + + const dbName = parse(config, () => {}); return client.db(dbName); });