2020-04-20 04:52:50 +00:00
|
|
|
// Copyright 2020 Emily J. / mudkipscience and contributors. Subject to the AGPLv3 license.
|
2020-04-20 03:02:10 +00:00
|
|
|
|
2020-04-04 06:59:22 +00:00
|
|
|
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) {
|
2020-04-18 14:23:50 +00:00
|
|
|
client.logger.error(`Could not connect to the database:\n ${err.stack}`)
|
2020-04-04 06:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|