Skip to content

Commit

Permalink
fix: More robust parsing of mongodb connection string. Use new url pa…
Browse files Browse the repository at this point in the history
…rser. (#1002)

* More robust parsing of mongodb connection string. Use new url parser.

* Set mongodb-core as a dependency when generating a mongodb connection
  • Loading branch information
sagannotcarl authored and daffl committed Sep 24, 2018
1 parent 8c2e49a commit 74b31df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/generator-feathers/generators/connection/index.js
Expand Up @@ -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':
Expand Down
@@ -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);
});

Expand Down

0 comments on commit 74b31df

Please sign in to comment.