diff --git a/lib/manager.js b/lib/manager.js index 9c2d4771..f3777f88 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -60,6 +60,10 @@ function Manager (uri, opts, fn) { opts = opts || {} + if (!opts.hasOwnProperty('useNewUrlParser')) { + opts.useNewUrlParser = true + } + this._collectionOptions = objectAssign({}, DEFAULT_OPTIONS, opts.collectionOptions || {}) delete opts.collectionOptions @@ -126,8 +130,6 @@ inherits(Manager, EventEmitter) * @private */ Manager.prototype.open = function (uri, opts, fn) { - opts.useNewUrlParser = true - MongoClient.connect(uri, opts, function (err, client) { if (err) { this._state = STATE.CLOSED diff --git a/test/monk.js b/test/monk.js index 45e080e6..9f1b50b4 100644 --- a/test/monk.js +++ b/test/monk.js @@ -154,3 +154,21 @@ test('oid from oid', (t) => { const oid = db.oid() t.is(db.oid(oid), oid) }) + +test('option useNewUrlParser should be true if not specified', (t) => { + return monk('127.0.0.1/monk-test').then((db) => { + t.is(db._connectionOptions.useNewUrlParser, true) + }) +}) + +test('option useNewUrlParser should be true if specified', (t) => { + return monk('127.0.0.1/monk-test', { useNewUrlParser: true }).then((db) => { + t.is(db._connectionOptions.useNewUrlParser, true) + }) +}) + +test('option useNewUrlParser should have the specified value', (t) => { + return monk('127.0.0.1/monk-test', { useNewUrlParser: false }).then((db) => { + t.is(db._connectionOptions.useNewUrlParser, false) + }) +})