我正在尝试执行“$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 [email protected] /cdn-cgi/l/email-protection if you need assistance.
为什么 $or 被检测为未知运算符?
只是因为 $or 应该是查询中的顶级运算符,如下所示:
db.collection.find({
"$or": [
{
"metadata.text": { "$regex": ".*hello.*" }
},
{
"metadata.text": { "$regex": ".*world.*" }
}
]
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)