Vous pouvez utiliser l'opérateur $ou
let filter = {
"$or":[
name: { $regex: new RegExp(`^${company.name}$`, 'i') },
company_code: { $regex: new RegExp(`^${company.company_code}$`, 'i')
]
}
}
cModel.find(filter, function (err, docs) {
if (docs.length) {
result.error = "Name already exists: " + company.name;
console.log("Name already exists", null);
let resp = api_respose.getSuccessResponse(process.env.WEB_URI, result.error);
resolve(resp);
}
else{
///saving here
}
consulter https://docs.mongodb.com/manual/reference/operator /requête/ou/ pour plus d'informations