TypeError: User.findOne is not a function

错误提示:

(node:2636) UnhandledPromiseRejectionWarning: TypeError: User.findOne is not a function
    at module.exports (D:\web\blog01\route\admin\user-modify-fn.js:8:27)
    at Layer.handle [as handle_request] (D:\web\blog01\node_modules\express\lib\router\layer.js:95:5)
    at next (D:\web\blog01\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (D:\web\blog01\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (D:\web\blog01\node_modules\express\lib\router\layer.js:95:5)
    at D:\web\blog01\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (D:\web\blog01\node_modules\express\lib\router\index.js:335:12)
    at next (D:\web\blog01\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (D:\web\blog01\node_modules\express\lib\router\index.js:174:3)
    at router (D:\web\blog01\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (D:\web\blog01\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (D:\web\blog01\node_modules\express\lib\router\index.js:317:13)
    at D:\web\blog01\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (D:\web\blog01\node_modules\express\lib\router\index.js:335:12)
    at next (D:\web\blog01\node_modules\express\lib\router\index.js:275:10)
    at guard (D:\web\blog01\middleware\loginGuard.js:27:9)
(node:2636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

错误原因:User.findOne is not a function

const User = require('../../model/user');
......
let user = await User.findOne({ _id: id });

require(’…/…/model/user’),获取的不是User对象,还包括其他对象,应改为:

const {User} = require('../../model/user');
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值