2
With that consultation:
const result = await Topic.find( { 'categorieName': { $regex: /^news/i } } )
I can return the categories with name news, the problem is that it is not always news, so I wanted to put a variable in place
How do I do that? I have a variable called category that is already receiving the value 'news', if I put in the console.log, so I tried this:
const result = await Topic.find(JSON.parse(`{ 'categorieName' : { $regex: /^${categoria}/i } }`));
But it didn’t work, what I’m doing wrong?
Ahhh understood, regular expressions would be like '', '/' and something else, right? What did I do wrong to replace the const result = await Topic.find( { 'categorieName': { $regex: / news/i } } ) ?? I tried this: https://hastebin.com/imacehigon.js But I got these errors: https://hastebin.com/apufayepav.makefile
– rogomazagu
you do something like: create regular expression
let re = new RegExp(
${category}[0-9]?, 'i');
and then pass it on the searchTopic.find({ categorieName: { $regex: re } });
– Costamilam
I was flying, using the wrong variable, thanks bro!
– rogomazagu