Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async init (mongoUrl: string) {
log.silly(PRE, `Mongo init()`)
await mongoose.connect(mongoUrl, {
server: { poolSize: 30 },
useNewUrlParser: true,
})
this.db = mongoose.connection
this.db.on('error', () => log.error('connection error'))
this.db.once('open', () => {
log.info(`Connected successfully!`)
})
}
public async release () {
log.silly(PRE, `Close mongo connection`)
if (!this.db) {
throw new Error(`mongoose connection has not init.`)
}
await this.db.close()
}