From e274ff01e9636270855478c37aff8a0e92f4c627 Mon Sep 17 00:00:00 2001 From: Raul Riera Date: Fri, 18 May 2018 20:49:11 -0400 Subject: [PATCH 1/2] Support for passing additional options --- packages/strapi-mongoose/lib/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/strapi-mongoose/lib/index.js b/packages/strapi-mongoose/lib/index.js index 51469672b4..d0f9ddefe4 100755 --- a/packages/strapi-mongoose/lib/index.js +++ b/packages/strapi-mongoose/lib/index.js @@ -39,7 +39,8 @@ module.exports = function (strapi) { port: 27017, database: 'strapi', authenticationDatabase: '', - ssl: false + ssl: false, + debug: false }, /** @@ -50,10 +51,11 @@ module.exports = function (strapi) { _.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => { const instance = new Mongoose(); const { uri, host, port, username, password, database } = _.defaults(connection.settings, strapi.config.hook.settings.mongoose); - const { authenticationDatabase, ssl } = _.defaults(connection.options, strapi.config.hook.settings.mongoose); + const { authenticationDatabase, ssl, debug } = _.defaults(connection.options, strapi.config.hook.settings.mongoose); // Connect to mongo database const connectOptions = {}; + const options = {}; if (!_.isEmpty(username)) { connectOptions.user = username; @@ -69,8 +71,14 @@ module.exports = function (strapi) { connectOptions.ssl = ssl === true || ssl === 'true'; + options.debug = debug === true || debug === 'true'; + instance.connect(uri || `mongodb://${host}:${port}/${database}`, connectOptions); + for (let key in options) { + instance.set(key, options[key]) + } + // Handle error instance.connection.on('error', error => { if (error.message.indexOf(`:${port}`)) { From bf4fa666ece518b0615c9b4109e5fda763c67c0f Mon Sep 17 00:00:00 2001 From: Raul Riera Date: Fri, 18 May 2018 21:04:24 -0400 Subject: [PATCH 2/2] Improved the syntax --- packages/strapi-mongoose/lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strapi-mongoose/lib/index.js b/packages/strapi-mongoose/lib/index.js index d0f9ddefe4..ffa26506de 100755 --- a/packages/strapi-mongoose/lib/index.js +++ b/packages/strapi-mongoose/lib/index.js @@ -69,9 +69,9 @@ module.exports = function (strapi) { connectOptions.authSource = authenticationDatabase; } - connectOptions.ssl = ssl === true || ssl === 'true'; + connectOptions.ssl = Boolean(ssl); - options.debug = debug === true || debug === 'true'; + options.debug = Boolean(debug); instance.connect(uri || `mongodb://${host}:${port}/${database}`, connectOptions);