我正在尝试执行“$ or”搜索以匹配两个正则表达式,如下所示:
{
"metadata.text": {
"$or": [
{
"$regex": ".*hello.*"
},
{
"$regex": ".*world.*"
}
]
}
}
我正在使用mlab.com,并收到以下错误消息:
MongoDB error: "Command failed with error 2: 'unknown operator: $or' on server ZZZZZZZ. The full response is { "ok" : 0.0, "errmsg" : "unknown operator: $or", "code" : 2, "codeName" : "BadValue" }." Please contact support@mlab.com if you need assistance.
为什么$或被检测为未知运算符?
最佳答案
仅仅因为$ or应该是查询中的顶级运算符,就像这样:
db.collection.find({
"$or": [
{
"metadata.text": { "$regex": ".*hello.*" }
},
{
"metadata.text": { "$regex": ".*world.*" }
}
]
})
关于mongodb - 为什么我的MongoDB $ or查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48014849/