how to use search_key
variable as field value instead of static value BRO
if(search_key!=''){
dbo.collection("assets").aggregate([
{
"$match": { $and: [ { status: 1 }, { $or: [ { maker_name : /^.*BRO.*$/i }, { serial_number : /^.*BRO.*$/i } ] } ] }
},
{
$lookup:
{
from: 'asset_type',
localField: 'asset_type',
foreignField: 'asset_type_id',
as: 'asset_type_details'
}
}
]).sort({_id:-1}).toArray(function(err, result) {
if (err) throw err;
res.status(200).json({'return_data': result });
db.close();
});
}