Skip to content

Commit 2379a42

Browse files
committed
fix(connection): throw helpful error when callback param to mongoose.connect() or mongoose.createConnection() is not a function
Fix #8556
1 parent 047fc94 commit 2379a42

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/connection.js

+6
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ Connection.prototype.openUri = function(uri, options, callback) {
579579
'`mongoose.connect()` or `mongoose.createConnection()` is a string.');
580580
}
581581

582+
if (callback != null && typeof callback !== 'function') {
583+
throw new MongooseError('3rd parameter to `mongoose.connect()` or ' +
584+
'`mongoose.createConnection()` must be a function, got "' +
585+
typeof callback + '"');
586+
}
587+
582588
const Promise = PromiseProvider.get();
583589
const _this = this;
584590

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if (global.MONGOOSE_DRIVER_PATH) {
1515
require('./driver').set(require('./drivers/node-mongodb-native'));
1616
}
1717

18+
const Document = require('./document');
1819
const Schema = require('./schema');
1920
const SchemaType = require('./schematype');
2021
const SchemaTypes = require('./schema/index');
@@ -24,7 +25,6 @@ const VALID_OPTIONS = require('./validoptions');
2425
const Types = require('./types');
2526
const Query = require('./query');
2627
const Model = require('./model');
27-
const Document = require('./document');
2828
const applyPlugins = require('./helpers/schema/applyPlugins');
2929
const get = require('./helpers/get');
3030
const legacyPluralize = require('mongoose-legacy-pluralize');
@@ -326,10 +326,10 @@ Mongoose.prototype.createConnection = function(uri, options, callback) {
326326
* @return {Promise} resolves to `this` if connection succeeded
327327
*/
328328

329-
Mongoose.prototype.connect = function() {
329+
Mongoose.prototype.connect = function(uri, options, callback) {
330330
const _mongoose = this instanceof Mongoose ? this : mongoose;
331331
const conn = _mongoose.connection;
332-
return conn.openUri(arguments[0], arguments[1], arguments[2]).then(() => _mongoose);
332+
return conn.openUri(uri, options, callback).then(() => _mongoose);
333333
};
334334

335335
/**

0 commit comments

Comments
 (0)