I have this Aggregation pipeline. I am able to get the data I need with additional function like sorting and pagination. I used $lookup to add documents I need from other collections.
[ { '$match': { status: [Object] } },
{ '$lookup': { from: 'users', as: 'owner', let: { owner: "$owner" }, pipeline: [
{ $match: { $expr: { $eq: ["$$owner", "$_id"] } } },
{ $unwind: { path:"$subscriptions", preserveNullAndEmptyArrays: false} },
{ $match: { "subscriptions.active": true } },
{
$lookup: {
from: "plans",
localField: "subscriptions.plan_id",
foreignField: "_id",
as: "subscriptions.plans"
}
},
] }},
{ '$unwind': { path: '$owner', preserveNullAndEmptyArrays: true } },
{ '$sort': { location: 1 } },
{ '$skip': 0 },
{ '$limit': 20 }
]
But now, I need to filter these results with search function. I want to use regex with case insensitive to match results. How can I use regex with $match? How can I use $gte and $lte with $match for date range?
I tried using $regexMatch like,
{$match: {$regexMatch: {new RegExp(variableName, 'i')}}
but failed.
Also on $lookup for plans, how can I use $match there to filter results that have only plans from regex?