【发布时间】:2021-01-21 23:47:07
【问题描述】:
我在 MongoDB 中有这样的简单数据
{
"_id": "eE-sOpegt",
"isApproved": true,
"isDttotWarningFlagRaised": false,
"fullname": "Gerald Bendryandre Sihotang",
"email": "email@gmail.com",
"password": "$2a$10$Uib2qpgLrzYAM4KmPdX/bOP6pBozJ6SDadCBSYoXY1JNcSJI7/3xC",
"phone": 6281234567890,
"registrationStep": 2,
"role": "user",
"__v": 0
}
查看phone,它是number 不是 string。
我想使用paginate在一个字段中搜索此数据
代码如下:
User.paginate({
$or: [
{ fullname: new RegExp('.*' + req.query.q + '.*', 'i') },
{ email: new RegExp('.*' + req.query.q + '.*', 'i') },
/* Here is the problem
When I comment this phone, it works and return data.
When its not commented, returns error
*/
// { phone: {$eq: Number(req.query.q) } }
]
}
...
我通过这个 URL 使用邮递员调用这个 APIlocalhost:8000/getUsersByQuery?q=gerald
当我评论{ phone }时它有效
但是当 phone 没有被评论时它会返回错误
如何获取phone号码的数据?
【问题讨论】:
-
你能分享一下错误吗?
标签: javascript node.js mongodb api mongoose