使用 insertMany
// 输入数据
{"list":[{"areaOfPharmacistBackup":"湖北省武汉市黄陂区","nameOfPharmacistBackup":"鲁**","typeOfPharmacistBackup":"中药学","scopeOfPharmacistBackup":"零售","unitOfPharmacistBackup":"XXX公司1","numberOfPharmacistBackup":"422212341234","validTimeOfPharmacistBackup":"2021-11-22"},{"areaOfPharmacistBackup":"陕西省西安市未央区","nameOfPharmacistBackup":"杨*","typeOfPharmacistBackup":"药学","scopeOfPharmacistBackup":"零售","unitOfPharmacistBackup":"XXX公司2","numberOfPharmacistBackup":"611212341234","validTimeOfPharmacistBackup":"2021-12-20"}]
}// 代码
let pharmacistBackups = req.body.list;
if (typeof pharmacistBackups === 'string') {pharmacistBackups = JSON.parse(pharmacistBackups);
}
PharmacistBackup.remove().then(() => PharmacistBackup.insertMany(pharmacistBackups)).then(() => res.send({code: '400000'})).catch(err => next(err));