Skip to content

Commit

Permalink
handle better useNewUrlParser option
Browse files Browse the repository at this point in the history
  • Loading branch information
mpangrazzi committed May 13, 2019
1 parent 8487800 commit 47e376c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/monk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 47e376c

Please sign in to comment.