Skip to content

Commit 47e376c

Browse files
committed
handle better useNewUrlParser option
1 parent 8487800 commit 47e376c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/manager.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function Manager (uri, opts, fn) {
6060

6161
opts = opts || {}
6262

63+
if (!opts.hasOwnProperty('useNewUrlParser')) {
64+
opts.useNewUrlParser = true
65+
}
66+
6367
this._collectionOptions = objectAssign({}, DEFAULT_OPTIONS, opts.collectionOptions || {})
6468
delete opts.collectionOptions
6569

@@ -126,8 +130,6 @@ inherits(Manager, EventEmitter)
126130
* @private
127131
*/
128132
Manager.prototype.open = function (uri, opts, fn) {
129-
opts.useNewUrlParser = true
130-
131133
MongoClient.connect(uri, opts, function (err, client) {
132134
if (err) {
133135
this._state = STATE.CLOSED

test/monk.js

+18
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,21 @@ test('oid from oid', (t) => {
154154
const oid = db.oid()
155155
t.is(db.oid(oid), oid)
156156
})
157+
158+
test('option useNewUrlParser should be true if not specified', (t) => {
159+
return monk('127.0.0.1/monk-test').then((db) => {
160+
t.is(db._connectionOptions.useNewUrlParser, true)
161+
})
162+
})
163+
164+
test('option useNewUrlParser should be true if specified', (t) => {
165+
return monk('127.0.0.1/monk-test', { useNewUrlParser: true }).then((db) => {
166+
t.is(db._connectionOptions.useNewUrlParser, true)
167+
})
168+
})
169+
170+
test('option useNewUrlParser should have the specified value', (t) => {
171+
return monk('127.0.0.1/monk-test', { useNewUrlParser: false }).then((db) => {
172+
t.is(db._connectionOptions.useNewUrlParser, false)
173+
})
174+
})

0 commit comments

Comments
 (0)