I am getting the following error
UnhandledPromiseRejectionWarning: MongoError: $regex has to be a string
Below is my code:
let dbData = await client
.db('skreem-final')
.collection('influencers')
.countDocuments({
firstName: {
$regex: !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
$options: 'i',
},
});
// console.log(name, !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(name));
console.log(dbData);
// });
Try enclosing your regex into " "
:
$regex: "!/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g",
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.