我正在尝试像下面那样在CouchDB上进行查询
[{
"selector": {
"docType": "student_details",
{
$or: ["studentName": {
"$regex": "John"
}, "studentAge": {
"$regex": "15"
}]
}
}
}]
但是它不起作用。在“ studentName”和“ studentAge”上创建索引。如果任何一个表达式都有结果,我都在尝试获取输出。
但是以下查询有效,
[{
"selector": {
"docType": "student_details",
"studentName": {
"$regex": "John"
}
}
}]
[这给了我约翰的studentName
的输出
如果要查找完全匹配,则不需要使用$regex
,$eq
运算符更适合。 selector
可以编写如下。
"selector": {
"$or": [
{
"studentName": {
"$eq": "John"
}
},
{
"studentAge": {
"$eq": 15
}
}
]
}
或更简单地使用隐式运算符。
"selector": {
"$or": [
{ "studentName": "John" },
{ "studentAge": 15 }
]
}
请注意,此解决方案假定
studentAge
的类型为number
。