I want to do a collection.find() with filter in MongoDB. However, I need to pass a variable inside my $in operator to have exactly this format :
{ '$in': [ /^S/ ] }
But I actually have this format :
{ '$in': [ '/^S/' ] }
With this code :
let term = req.query.term;
console. log ("term:", term);
const filter = {
"firstname": { $in: ("/^ + term + "/"] }
};
console. log(filter);
const answer = await collection.find (filter). toArray();