mongoose pool connection code example

Example: mongoose database pooling

import mongoose from 'mongoose'

	mongoose.connect(process.env.MONGO_URI, {
		minPoolSize: 1,
		maxPoolSize: 20,
		compression: { compressors: ['zlib'] },
		useUnifiedTopology: true,
		useNewUrlParser: true,
		useFindAndModify: false,
		socketTimeoutMS: 60000,
		serverSelectionTimeoutMS: 60000,
		loggerLevel: 'error'
	})

	mongoose.connection.on('connecting', () => consola.info('database connecting'))
	mongoose.connection.on('connected', () => consola.success('database connected'))
	mongoose.connection.on('disconnecting', () => consola.info('database disconnecting'))
	mongoose.connection.on('disconnected', () => consola.info('database disconnected'))
	mongoose.connection.on('error', () => consola.error('database error'))