U kunt de $or-operator
. gebruiken 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
}
raadpleeg https://docs.mongodb.com/manual/reference/operator /query/of/ voor meer info