在我的应用中,我尝试使用.findOne
,但我收错了。这是我的错误: -
TypeError: User.findOne is not a function
at Strategy._verify (/Users/AES/twitterm/config/passport.js:21:8)
at Strategy.authenticate (/Users/AES/twitterm/node_modules/passport-local/lib/strategy.js:88:12)
at attempt (/Users/AES/twitterm/node_modules/passport/lib/middleware/authenticate.js:361:16)
at authenticate (/Users/AES/twitterm/node_modules/passport/lib/middleware/authenticate.js:362:7)
at Layer.handle [as handle_request] (/Users/AES/twitterm/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/AES/twitterm/node_modules/express/lib/router/route.js:137:13)
at next (/Users/AES/twitterm/node_modules/express/lib/router/route.js:131:14)
at Route.dispatch (/Users/AES/twitterm/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/AES/twitterm/node_modules/express/lib/router/layer.js:95:5)
at /Users/AES/twitterm/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/AES/twitterm/node_modules/express/lib/router/index.js:335:12)
at next (/Users/AES/twitterm/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Users/AES/twitterm/node_modules/express/lib/router/index.js:174:3)
at router (/Users/AES/twitterm/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/Users/AES/twitterm/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/AES/twitterm/node_modules/express/lib/router/index.js:317:13)
此链接中的代码文件https://www.dropbox.com/s/gbjtc7ilm9wnzj2/passport.js?dl=0 我想要选择此错误
答案 0 :(得分:1)
就在我的脑海中,看起来您从未导入Mongoose以便能够在模型上使用findOne
方法。
答案 1 :(得分:0)
您的代码将其作为FindOne。尝试改变它findOne
它也不像猫鼬被导入。
npm i --save mongoose
并导入
const mongoose = require('mongoose');
答案 2 :(得分:0)
可能是因为您没有使用正确的猫鼬模型,或者您的猫鼬模型未正确使用。
只有有效的猫鼬模型才有findOne
函数