Error handling promise save unique data in mongoDB (ValidationError)
You can handle the error with catch
to avoid this error:
function addDB(data) { return new Promise(() => { const bar = new My({ ...data }); bar.save().then(() => console.log('success')).catch(err=>console.log(err)) });