Currently, I am trying to query my Mongoose database with a search parameter where the title matches the "customTitle" extracted from the URL.
The search function works perfectly fine when searching for all items using
Article.find(err, foundArticles) =>
. However, when attempting to specifically search for records containing the "customTitle" variable using Article.find({title:/customTitle/i}, (err, foundArticles) => {
, I end up receiving an empty response.
My goal here is to retrieve a response that includes all items containing the "customTitle" variable within any record in the database.
app.route("/:customTitle")
.get(function(req, res){
const customTitle = _.capitalize(req.params.customTitle);
Article.find({title:/customTitle/i}, (err, foundArticles) => {
if (!err){
res.send(foundArticles);
console.log(typeof customTitle +" ", customTitle);
console.log(foundArticles);
} else {
res.send(err);
}
});
If you could help me identify the issue at hand, I would greatly appreciate it. Thank you.