Skip to content

Commit

Permalink
Merge pull request #9598 from AbdelrahmanHafez/gh-9597
Browse files Browse the repository at this point in the history
fix(connection): connect and disconnect can be used destructured re #9597
  • Loading branch information
vkarpov15 authored Nov 29, 2020
2 parents 5d7a28d + 5ff54cc commit c956bc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Mongoose.prototype.connect = function(uri, options, callback) {
const _mongoose = this instanceof Mongoose ? this : mongoose;
const conn = _mongoose.connection;

return this._promiseOrCallback(callback, cb => {
return _mongoose._promiseOrCallback(callback, cb => {
conn.openUri(uri, options, err => {
if (err != null) {
return cb(err);
Expand All @@ -359,7 +359,7 @@ Mongoose.prototype.connect = function(uri, options, callback) {
Mongoose.prototype.disconnect = function(callback) {
const _mongoose = this instanceof Mongoose ? this : mongoose;

return this._promiseOrCallback(callback, cb => {
return _mongoose._promiseOrCallback(callback, cb => {
let remaining = _mongoose.connections.length;
if (remaining <= 0) {
return cb(null);
Expand Down
14 changes: 14 additions & 0 deletions test/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,4 +1239,18 @@ describe('connections:', function() {
});
});


it('can use destructured `connect` and `disconnect` (gh-9597)', function() {
return co(function* () {
const m = new mongoose.Mongoose;
const connect = m.connect;
const disconnect = m.disconnect;

const errorOnConnect = yield connect('mongodb://localhost:27017/test_gh9597').then(() => null, err => err);
assert.ifError(errorOnConnect);

const errorOnDisconnect = yield disconnect().then(() => null, err => err);
assert.ifError(errorOnDisconnect);
});
});
});

0 comments on commit c956bc2

Please sign in to comment.