mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 09:47:46 +00:00
Merge pull request #1181 from raulriera/additional-variables-mongoose
Support for passing additional variables into mongoose
This commit is contained in:
commit
bae8073c7b
@ -39,7 +39,8 @@ module.exports = function (strapi) {
|
|||||||
port: 27017,
|
port: 27017,
|
||||||
database: 'strapi',
|
database: 'strapi',
|
||||||
authenticationDatabase: '',
|
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) => {
|
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => {
|
||||||
const instance = new Mongoose();
|
const instance = new Mongoose();
|
||||||
const { uri, host, port, username, password, database } = _.defaults(connection.settings, strapi.config.hook.settings.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
|
// Connect to mongo database
|
||||||
const connectOptions = {};
|
const connectOptions = {};
|
||||||
|
const options = {};
|
||||||
|
|
||||||
if (!_.isEmpty(username)) {
|
if (!_.isEmpty(username)) {
|
||||||
connectOptions.user = username;
|
connectOptions.user = username;
|
||||||
@ -67,10 +69,16 @@ module.exports = function (strapi) {
|
|||||||
connectOptions.authSource = authenticationDatabase;
|
connectOptions.authSource = authenticationDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectOptions.ssl = ssl === true || ssl === 'true';
|
connectOptions.ssl = Boolean(ssl);
|
||||||
|
|
||||||
|
options.debug = Boolean(debug);
|
||||||
|
|
||||||
instance.connect(uri || `mongodb://${host}:${port}/${database}`, connectOptions);
|
instance.connect(uri || `mongodb://${host}:${port}/${database}`, connectOptions);
|
||||||
|
|
||||||
|
for (let key in options) {
|
||||||
|
instance.set(key, options[key])
|
||||||
|
}
|
||||||
|
|
||||||
// Handle error
|
// Handle error
|
||||||
instance.connection.on('error', error => {
|
instance.connection.on('error', error => {
|
||||||
if (error.message.indexOf(`:${port}`)) {
|
if (error.message.indexOf(`:${port}`)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user