mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 21:54:24 +00:00
Add database uri configuration #602
This commit is contained in:
parent
1f3efc6416
commit
fe87be7793
@ -5,6 +5,7 @@
|
||||
"connector": "strapi-mongoose",
|
||||
"settings": {
|
||||
"client": "mongo",
|
||||
"uri": "${process.env.DATABASE_URI || ''}",
|
||||
"host": "${process.env.DATABASE_HOST || 'localhost'}",
|
||||
"port": "${process.env.DATABASE_PORT || 27017}",
|
||||
"database": "${process.env.DATABASE_NAME || 'production'}",
|
||||
|
||||
@ -40,7 +40,7 @@ module.exports = function (strapi) {
|
||||
initialize: cb => {
|
||||
_.forEach(_.pickBy(strapi.config.connections, {connector: 'strapi-mongoose'}), (connection, connectionName) => {
|
||||
const instance = new Mongoose();
|
||||
const { 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);
|
||||
|
||||
// Connect to mongo database
|
||||
const connectOptions = {}
|
||||
@ -50,7 +50,8 @@ module.exports = function (strapi) {
|
||||
connectOptions.pass = password
|
||||
}
|
||||
}
|
||||
instance.connect(`mongodb://${host}:${port}/${database}`, connectOptions);
|
||||
|
||||
instance.connect(uri || `mongodb://${host}:${port}/${database}`, connectOptions);
|
||||
|
||||
// Handle error
|
||||
instance.connection.on('error', error => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user