Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .findOne不是一个函数_Javascript_Node.js - Fatal编程技术网

Javascript .findOne不是一个函数

Javascript .findOne不是一个函数,javascript,node.js,Javascript,Node.js,在我的应用程序中,我尝试使用.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 atte

在我的应用程序中,我尝试使用.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)
以及此链接中的代码文件 我想选择此错误

您的代码将其设置为FindOne。试着把它改一下

看起来猫鼬也不是进口的

npm i --save mongoose
然后导入它

const mongoose = require('mongoose');

不经意间,您似乎从未导入过Mongoose以便能够在模型上使用findOne方法。

这可能是因为您没有使用正确的Mongoose模型,或者您的Mongoose模型没有正确使用


只有有效的mongoose模型才有findOne函数

如何导入?