I'm using .create() to add multiple records to the collection from an array .
if one of the records already exist i managed to show an error :
await Field.create(fieldArr, function (error,items) {
if(error && error.message.indexOf('duplicate key error') !== -1){
return res.status(400).json({message:'EXIST'})
}
// no error contiune
})
this is working fine but If the error occurred the other fields that don't exist will get added.
is there any way to stop creating the records if one or many of the items in the array exist?