您好,我的问题是我想使用 mongoose 的搜索查询。但我想使用查询发出获取请求。为什么这是不可能的?我不明白这个错误。我正在使用 5.10.0 版的猫鼬。我不想将其作为发布请求进行,也不想使用 req.body。谁能帮我?
这是我的代码:
export const searching = (req: Request, res: Response) => {
Company.find({ $text: { $search: req.query } }).exec((err, docs) => {
if (docs) {
res.status(200).json(docs)
} else {
console.log(err)
}
})
}
Run Code Online (Sandbox Code Playgroud)
我的错误信息:
(property) $search: string
No overload matches this call.
The last overload gave the following error.
Type 'ParsedQs' is not assignable to type 'string'.ts(2769)
Run Code Online (Sandbox Code Playgroud)