Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在nodejs中,使用$or运算符进行简单的查找查询_Node.js_Mongodb_Express - Fatal编程技术网

Node.js 在nodejs中,使用$or运算符进行简单的查找查询

Node.js 在nodejs中,使用$or运算符进行简单的查找查询,node.js,mongodb,express,Node.js,Mongodb,Express,我尝试使用mongodb数据库和简单的find with or操作符查找数据 错误:- 获取结果时出错MongoError:未知运算符:$或 主席表数据:- _id: 1 is_chairman: "1" role: "2" name: "amit" mobile_no: 74056072323 password: "$2a$10$VqCa4hoTefkrmKSvYsI.GOa/lghnGDk74c7Z.1DMeVmqp/q2yH3.S" society_name: "Jay Somnath"

我尝试使用mongodb数据库和简单的find with or操作符查找数据

错误:-

获取结果时出错MongoError:未知运算符:$或

主席表数据:-

 _id: 1
is_chairman: "1"
role: "2"
name: "amit"
mobile_no: 74056072323
password: "$2a$10$VqCa4hoTefkrmKSvYsI.GOa/lghnGDk74c7Z.1DMeVmqp/q2yH3.S"
society_name: "Jay Somnath"
created_at: 2019 - 04 - 23 07: 52: 02.021
updated_at: 2019 - 04 - 23 07: 52: 02.021

_id: 2
is_chairman: "2"
role: "2"
name: "karan raval"
mobile_no: 906712323233
password: "$2a$10$SMI374aSyLwAoEZJEvzzDOH0qJ6p4dqd47.jxUjPFbUTQczsWSeUS"
society_name: "pusph"
created_at: 2019 - 04 - 23 08: 14: 56.210
updated_at: 2019 - 04 - 23 08: 14: 56.211

_id: 3
is_chairman: "1"
role: "2"
name: "manthan"
mobile_no: 906545454
password: "$2a$10$SMI374aSyLwAoEZJEvzzDOH0qJ6p4dqd47.jxUjPFbUTQczsWSeUS"
society_name: "Jay"
created_at: 2019 - 04 - 23 08: 14: 56.210
updated_at: 2019 - 04 - 23 08: 14: 56.211

_id: 4
is_chairman: "2"
role: "2"
name: "mukesh"
mobile_no: 9043435676
password: "$2a$10$SMI374aSyLwAoEZJEvzzDOH0qJ6p4dqd47.jxUjPFbUTQczsWSeUS"
society_name: "krishnakung"
created_at: 2019 - 04 - 23 08: 14: 56.210
updated_at: 2019 - 04 - 23 08: 14: 56.211
我试试这个:

searchStr =  {"$or": [{'name':'jay'},
                      {'society_name':'jay'}
                        ]}
Chairman.find({is_chairman: "1"},searchStr,function(err,c){
     console.log(c);
}
我想得到这样的结果

 is_chairman == 1 and $or: [{'name':'jay'},{'society_name':'jay'}]

对于不区分大小写的搜索,您可以尝试:

对于区分大小写的搜索:

Chairman.find({
    $and: [
        {"is_chairman" : "1"},
        { $or: [
                {'name': "jay" },
                {"society_name" : "jay" }
            ]
        }
    ]
})

对于不区分大小写的搜索,您可以尝试:

对于区分大小写的搜索:

Chairman.find({
    $and: [
        {"is_chairman" : "1"},
        { $or: [
                {'name': "jay" },
                {"society_name" : "jay" }
            ]
        }
    ]
})
主席.find({is_主席:“1”),{$or:[{'name':'jay',{'society_name':'jay'}}
应该是
主席.find({is_主席:“1”,$or:[{'name':'jay'},{'society_name':'jay'}}
其中$or是
is_chirman
主席的兄弟姐妹.find({is_主席:“1”,$or:['name':'jay'},{'
应该是
主席。查找({is_主席:“1”、$or:[{'name':'jay'}、{'society_name':'jay'}})
其中$or是
is_chirman的兄弟姐妹