相关疑难解决方法(0)

这个错误说明了什么?类型 'ParsedQs' 不可分配给类型 'string'

您好,我的问题是我想使用 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)

javascript mongoose mongodb express typescript

3
推荐指数
2
解决办法
7307
查看次数

标签 统计

express ×1

javascript ×1

mongodb ×1

mongoose ×1

typescript ×1