在MongoDB中我有2个条件
第一个条件:
"\"userfullname\":{$regex : \"" + filtertext + "\", $options: 'i'}";
第二个条件:
"\"email\":{$regex : \"" + filtertext + "\", $options: 'i'}";
我需要对此声明进行OR条件,所以我所做的是:
matchquery = matchquery + "\"userfullname\":{$regex : \"" + filtertext + "\", $options: 'i'}"+["%OR:"]+"\"email\":{$regex : \"" + filtertext + "\", $options: 'i'}";
但当然没有用。我怎样才能做到这一点?
答案 0 :(得分:0)
使用 $or
运算符。您基本上想要创建一个具有
[(ngModel)]="user.name"
如果var matchquery = {
'$or': [
{ 'userfullname': { '$regex': \filtertext\, '$options': 'i' } },
{ 'email': { '$regex': \filtertext\, '$options': 'i' } }
]
}
是变量,则可以使用 RegExp
构造函数创建正则表达式对象,以便将文本与模式匹配。例如:
filtertext
要对查询进行字符串化,您可以尝试:
var filtertext = "foo";
var rgx = new RegExp(filtertext, "i");
var matchquery = {
"$or": [
{ "userfullname": rgx },
{ "email": rgx }
]
};
答案 1 :(得分:0)
使用Or运算符&像这样创建它:
<script>
$(function () {
var employeeNameList = [
"Abishek Chandrasekar", "Bharat", "Deepak", "Eric",
"Fizil", "Gowtham", "Harbajan",
"Akshara", "Roshini"
];
var employeeIDList = [
"SF1010", "SF2010", "SF3010", "SF4010",
"SF5010", "SF6010", "SF7010",
"SF9010", "SF8010"
];
var emaiIDList = [
"abishek.chandrasekar@syncfusion.com", "bharath@syncfusion.com", "deepak@syncfusion.com", "eric@syncfusion.com",
"fizil@syncfusion.com", "gowtham@syncfusion.com", "harbajan@syncfusion.com",
"akshara@syncfusion.com", "roshini@syncfusion.com"
];
$('#EmployeeNameSearch').ejAutocomplete({
width: "800px",
dataSource: employeeNameList /*I wanna change this list namebased on the selected category in dropdown*/
});
});