2019-05-29 05:21:06 -04:00
|
|
|
const mongoose = require('mongoose')
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
|
2019-11-18 09:03:20 -05:00
|
|
|
const POOL_SIZE = Settings.mongo.poolSize
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
mongoose.connect(
|
|
|
|
Settings.mongo.url,
|
|
|
|
{
|
2019-11-18 09:03:20 -05:00
|
|
|
poolSize: POOL_SIZE,
|
|
|
|
config: { autoIndex: false },
|
|
|
|
useMongoClient: true,
|
|
|
|
appname: 'web'
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
mongoose.connection.on('connected', () =>
|
2019-11-18 09:03:20 -05:00
|
|
|
logger.log(
|
|
|
|
{
|
|
|
|
url: Settings.mongo.url,
|
|
|
|
poolSize: POOL_SIZE
|
|
|
|
},
|
|
|
|
'mongoose default connection open'
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
mongoose.connection.on('error', err =>
|
|
|
|
logger.err({ err }, 'mongoose error on default connection')
|
|
|
|
)
|
|
|
|
|
|
|
|
mongoose.connection.on('disconnected', () =>
|
|
|
|
logger.log('mongoose default connection disconnected')
|
|
|
|
)
|
|
|
|
|
|
|
|
if (process.env.MONGOOSE_DEBUG) {
|
|
|
|
mongoose.set('debug', (collectionName, method, query, doc) =>
|
|
|
|
logger.debug('mongoose debug', { collectionName, method, query, doc })
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mongoose
|