Do you want to request a feature or report a bug?
bug
What is the current behavior?
I recently found that mongoose does not allow a document to be saved if a previous save hasn't completed yet. Makes total sense. That being said, the ParallelSaveError does not get caught in a try/catch.
try {
document.save()
document.save()
} catch(err) {
console.log("There was an error")
console.log(err)
}
"There was an error" never gets logged.
What is the expected behavior?
The catch should catch the ParallelSaveError and "There was an error" should be logged.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose: 5.6.5
Node.js: 10.15.2
ParallelSaveError
must be async, because Mongoose checks for parallel saves after pre hooks run. You should await
on save()
, and then you can try/catch
the error.
try {
await document.save()
await document.save()
} catch(err) {
console.log("There was an error")
console.log(err)
}