Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
connect with mongoose using async/await
const mongoose = require('mongoose')
mongoose.Promise = Promise
mongoose.connection.on('connected', () => {
console.log('Connection Established')
})
mongoose.connection.on('reconnected', () => {
console.log('Connection Reestablished')
})
mongoose.connection.on('disconnected', () => {
console.log('Connection Disconnected')
})
mongoose.connection.on('close', () => {
console.log('Connection Closed')
})
mongoose.connection.on('error', (error) => {
console.log('ERROR: ' + error)
})
const run = async () => {
await mongoose.connect('mongodb://localhost:27017/emilioriosvz', {
autoReconnect: true,
reconnectTries: 1000000,
reconnectInterval: 3000
})
}
run().catch(error => console.error(error))
@enheit

This comment has been minimized.

Copy link

@enheit enheit commented Mar 15, 2020

Thank you (:

@costa86

This comment has been minimized.

Copy link

@costa86 costa86 commented Apr 9, 2020

That was very helpfull! Thanks a lot!

@afcajamarcar

This comment has been minimized.

Copy link

@afcajamarcar afcajamarcar commented May 13, 2020

Thank you very much kind sir.

@djibba22

This comment has been minimized.

Copy link

@djibba22 djibba22 commented Jul 30, 2020

awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.