From 7965494cb32c5105246480297532037f01573f17 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 26 Jul 2018 18:17:32 -0400 Subject: [PATCH] fix(connection): throw helpful error when using legacy `mongoose.connect()` syntax Fix #6756 --- lib/connection.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/connection.js b/lib/connection.js index 9488bbcca53..069b4af543d 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -414,6 +414,13 @@ Connection.prototype.openUri = function(uri, options, callback) { options = null; } + if (['string', 'number'].indexOf(typeof options) !== -1) { + throw new MongooseError('Mongoose 5.x no longer supports ' + + '`mongoose.connect(host, dbname, port)` or ' + + '`mongoose.createConnection(host, dbname, port)`. See ' + + 'http://mongoosejs.com/docs/connections.html for supported connection syntax'); + } + const Promise = PromiseProvider.get(); const _this = this;