const getModels = asyncHandler(async (req, res) => { const { modelName } = req.query; const dealership = await Dealership.aggregate([ { $match: { _id: req.user.dealership } }, { $project: { models: { $filter: { input: "$models", as: "models", cond: { $regexMatch: { input: "$$models.modelName", regex: `^${modelName}`, options: "i", }, }, }, }, }, }, ]); const models = dealership[0].models; return res.status(200).json({ success: true, quesData: models, }); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter