rename helpers utils
This commit is contained in:
parent
9b58684c16
commit
2958652eff
4 changed files with 0 additions and 0 deletions
36
utils/mongoose.js
Normal file
36
utils/mongoose.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const mongoose = require('mongoose')
|
||||
|
||||
module.exports = {
|
||||
init: (client) => {
|
||||
const options = {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
autoIndex: false,
|
||||
family: 4
|
||||
}
|
||||
|
||||
try {
|
||||
mongoose.connect(client.config.mongoDB, options)
|
||||
mongoose.set('useFindAndModify', false)
|
||||
mongoose.Promise = global.Promise
|
||||
} catch (err) {
|
||||
client.logger.fatal(`Could not connect to the database:\n ${err.stack}`)
|
||||
}
|
||||
|
||||
mongoose.connection.on('connected', () => {
|
||||
client.logger.info('Connected to the database.')
|
||||
})
|
||||
|
||||
mongoose.connection.on('err', err => {
|
||||
client.logger.error(`Database connection error:\n ${err.stack}`)
|
||||
})
|
||||
|
||||
mongoose.connection.on('disconnected', () => {
|
||||
client.logger.info('Disconected from the database.')
|
||||
})
|
||||
|
||||
mongoose.connection.on('reconnected', () => {
|
||||
client.logger.info('Reconnected to the database.')
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue