gpt4 book ai didi

node.js - 在nodejs中使用$or运算符简单查找查询

转载 作者:太空宇宙 更新时间:2023-11-04 01:31:59 26 4
gpt4 key购买 nike

我尝试使用 mongodb 数据库通过简单的或运算符查找来查找数据。

错误:-

error while getting resultMongoError: unknown operator: $or

主席表数据:-

 _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'}]

最佳答案

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

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

对于区分大小写的搜索:

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

关于node.js - 在nodejs中使用$or运算符简单查找查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55808864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com