mongoose concatinate two fields and then run search query code example
Example: mongoose search combine fields
db.collection.aggregate([
{
$addFields: {
nameFilter: {
$concat: ["$name", " ", "$surname"],
},
locationFilter: {
$concat: ["$workplace", " ", "$location"],
},
},
},
{
$match: {
nameFilter: {
$regex: req.query.name,
$options: "i",
},
locationFilter: {
$regex: req.query.place,
$options: "i",
},
},
},
]);