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",
},
},
},
]);