Skip to content

Instantly share code, notes, and snippets.

@itashdv
Created April 16, 2020 18:41
Show Gist options
  • Select an option

  • Save itashdv/da87bbe7615f64277b1c8654b91daf54 to your computer and use it in GitHub Desktop.

Select an option

Save itashdv/da87bbe7615f64277b1c8654b91daf54 to your computer and use it in GitHub Desktop.
Using promises in Mongoose
Schema.methods.saveAsync = function () {
return new Promise((resolve, reject) => {
this.save((err) => {
if (err) return reject(err)
resolve(this)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment