Можете да използвате оператор $or
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
}
виж https://docs.mongodb.com/manual/reference/operator /заявка/или/ за повече информация