Javascript 未解析的函数或方法findOne()
我有一个user.js文件,用于我的网站中的用户模型。 这是用户模式:Javascript 未解析的函数或方法findOne(),javascript,node.js,mongodb,function,Javascript,Node.js,Mongodb,Function,我有一个user.js文件,用于我的网站中的用户模型。 这是用户模式: var UserSchema = mongoose.Schema({ username: { type: String, index:true }, password: { type: String }, email: { type: String }, name: { type: Stri
var UserSchema = mongoose.Schema({
username: {
type: String,
index:true
},
password: {
type: String
},
email: {
type: String
},
name: {
type: String
},
avatar: {
type: String
}
});
UserSchema.plugin(passportLocalMongoose);
var User = module.exports = mongoose.model('User', UserSchema);
当我想在另一个文件中为用户配置文件使用函数findOne()时,它给出了我在标题中键入的错误
这是文件的代码:
var User = require('../models/user.js');
router.get("/:username", function(req,res){
User.findOne(req.params.username, function(err,foundUser){
if(err){
req.flash("error", "Something went wrong.");
return res.redirect("/");
}
res.render("show",{user:foundUser});
})
});
它仍然给我同样的错误。它好像不认识这个函数…没关系,它现在可以工作了,即使它说它没有解决。。。谢谢您!
User.findOne({where: {username: req.params.username}}, function(err,foundUser){
//rest of code
})