I think you can use regex in MongoDB. The following is the code for what you're looking for (escapeRegex function source here):
function escapeRegex(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
router.get("/", function(req, res) {
if (req.query.search) {
const regex = new RegExp(escapeRegex(req.query.search), 'gi');
Jobs.find({ "name": regex }, function(err, foundjobs) {
if(err) {
console.log(err);
} else {
res.render("jobs/index", { jobs: foundjobs });
}
});
}
}
With the help of package like search-index for search can help you to optimize your application's performance, with the added benefit of searching word stems (like returning "found" from "find").
If you want to learn full-stack web development in detail, this Full Stack Developer Course is the perfect fit for you.