[英]MongoDB: Find all records with special characters in a particular field
I am getting the following error我收到以下错误
UnhandledPromiseRejectionWarning: MongoError: $regex has to be a string
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",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.