Skip to content

Commit

Permalink
fix(url_parser): support a default database on mongodb+srv uris
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Mar 23, 2018
1 parent 02729dc commit 6d39b2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ module.exports = function(url, options, callback) {
let connectionString = connectionStrings.join(',') + '/';
let connectionStringOptions = [];

// Add the default database if needed
if (result.path) {
let defaultDb = result.path.slice(1);
if (defaultDb.indexOf('?') !== -1) {
defaultDb = defaultDb.slice(0, defaultDb.indexOf('?'));
}

connectionString += defaultDb;
}

// Default to SSL true
if (!options.ssl && !result.search) {
connectionStringOptions.push('ssl=true');
Expand Down
9 changes: 8 additions & 1 deletion test/functional/mongodb_srv_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ function getTests() {
.map(x => [path.basename(x[0], '.json'), JSON.parse(x[1])]);
}

describe('DNS and TXT record tests', function() {
describe('mongodb+srv (spec)', function() {
it('should parse a default database', function(done) {
parse('mongodb+srv://test5.test.build.10gen.cc/somedb', (err, result) => {
expect(result.dbName).to.eql('somedb');
done();
});
});

getTests().forEach(function(test) {
if (!test[1].comment) test[1].comment = test[0];

Expand Down

0 comments on commit 6d39b2a

Please sign in to comment.